|
|
|
|
|
by mschuetz
2589 days ago
|
|
Rearanged your js sample a bit, now it runs in ~26ms (first time) and ~11ms (subsequent times) instead of ~220ms in the chrome developer console. {
let a = Math.pow(2, 1023)
let t = performance.now();
let max = 1e7;
for (let i = 0; i < max; i++) {
a += i;
}
console.log(performance.now() - t);
}
Main problem was, that you should declare a with let.That benchmark is a bit strange/flawed anyway. You're initializing a as pow(2, 1023), then adding numbers in the loop. But since a is already such a large double value, the result won't change. The numbers you add are too small to make a dent in the value of a, likely because a isn't an integer. It's a double with a limited precision for large integer values. |
|