Test name | Executions per second |
---|---|
Re create array (declared using "let") | 2973.2 Ops/sec |
Empty array (declared using "const") | 2892.5 Ops/sec |
<!--your preparation HTML code goes here-->
/*your preparation JavaScript code goes here
To execute async code during the script preparation, wrap it as function globalMeasureThatScriptPrepareFunction, example:*/
async function globalMeasureThatScriptPrepareFunction() {
// This function is optional, feel free to remove it.
// await someThing();
}
function isPrime(num) {
for (let i = 2, s = Math.sqrt(num); i <= s; i++) {
if (num % i === 0) {
return false;
}
}
return num > 1;
}
const size = 10000;
let primeNumbers = [];
for (var i = 0; i < size; i++) {
if (isPrime(i)) {
primeNumbers.push(i);
}
if (primeNumbers.length > 10) {
primeNumbers = [];
}
}
const size = 10000;
const primeNumbers = [];
for (var i = 0; i < size; i++) {
if (isPrime(i)) {
primeNumbers.push(i);
}
if (primeNumbers.length > 10) {
primeNumbers.splice(0, primeNumbers.length);
}
}