我试图证明一个操作比2个操作花费的时间少,所以我使用下面的步骤
var a=performance.now();
c=10+40;
d=80+90;
var b=performance.now();
console.log(b-a);
a=performance.now();
l=10+40;
b=performance.now();
console.log(b-a);
但结果因执行而异,如下所示
0.009999997913837433
0.034999996423721313
//second execution
0.010000001639127731
0
//Thirdexecution
0.009999997913837433
0.015000000596046448
即使我尝试了
console.time('a');
c=10+40;d=80+90;
console.timeEnd('a');
console.time('b');
l=10+40;
console.timeEnd('b');
即使是相同的操作也没有给出确切的值
z=performance.now()
a=10+60;
x=performance.now()
console.log(x-z)
输出:
//on first execution
0.009999999776482582
//on second execution
0.015000000596046448
结果仍然相同,请介绍一下这个话题。