jsPerf.app is an online JavaScript performance benchmark test runner & jsperf.com mirror. It is a complete rewrite in homage to the once excellent jsperf.com now with hopefully a more modern & maintainable codebase.
jsperf.com URLs are mirrored at the same path, e.g:
https://jsperf.com/negative-modulo/2
Can be accessed at:
https://jsperf.app/negative-modulo/2
different ways to get prime numbers below n
function prime1(num) {
var primes = [];
loop: for (var i = 2; i <= num; i++) {
for (var j = 0; j <= primes.length; j++)
if (i % primes[j] === 0) continue loop;
primes.push(i);
}
return primes;
}
function primeNam(num) {
// Generate an array containing every prime number between 0 and the num specified (inclusive)
var numbers = Array.apply(null, {length: num + 1}).map(Number.call, Number).slice(2);
var sqrt = Math.ceil(Math.sqrt(num));
// Sieve of Eratosthenes
for (var i = 0; numbers[i] < sqrt; i++) {
numbers = numbers.filter(n => (n === numbers[i] || n%numbers[i]));
}
return numbers;
}
Ready to run.
Test | Ops/sec | |
---|---|---|
prime1 |
| ready |
nam |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.