Test name | Executions per second |
---|---|
Table lookup | 273325.5 Ops/sec |
Math.pow | 145618.7 Ops/sec |
bitwise (1 << n) | 6254165.0 Ops/sec |
var POWERS = [
1,2,4,8,16,32,64,128,256,512,1024,2048,4096,8192,16384,32768,65536,131072,262144,524288,1048576,2097152,4194304,8388608,16777216,33554432
];
let cnt = POWERS.length;
let x;
for(let i =0;i<cnt;i++){
x = POWERS[i];
}
let cnt = POWERS.length;
let x;
for(let i =0;i<cnt;i++){
x = Math.pow(2,i);
}
let cnt = POWERS.length;
let x;
for(let i =0;i<cnt;i++){
x = (1 << i);
}