Javascript 测试了来自jsforcats.com的代码片段。firefox的执行速度似乎很慢。为什么?

Javascript 测试了来自jsforcats.com的代码片段。firefox的执行速度似乎很慢。为什么?,javascript,performance,google-chrome,firefox,execution,Javascript,Performance,Google Chrome,Firefox,Execution,Chrome vs Firefox。当前版本。在关闭附加组件的情况下进行测试。刷新了Firefox function measureLoopSpeed() { var count = 0 function addOne() { count = count + 1 } // Date.now() returns a big number representing the number of // milliseconds that have elapsed since Jan 0

Chrome vs Firefox。当前版本。在关闭附加组件的情况下进行测试。刷新了Firefox

function measureLoopSpeed() {
  var count = 0
  function addOne() { count = count + 1 }

  // Date.now() returns a big number representing the number of
  // milliseconds that have elapsed since Jan 01 1970
  var now = Date.now()

  // Loop until Date.now() is 1000 milliseconds (1 second) or more into
  // the future from when we started looping. On each loop, call addOne
  while (Date.now() - now < 1000) addOne()

  // Finally it has been >= 1000ms, so let's print out our total count
  console.log(count)
}
undefined

//On Firefox console
measureLoopSpeed()
4227461 debugger eval code:14:11
undefined
measureLoopSpeed()
4103189 debugger eval code:14:11
undefined

//On Chrome console
undefined
measureLoopSpeed()
11193127
undefined
measureLoopSpeed()
11153367
undefined
measureLoopSpeed()
11159575
函数measureLopSpeed(){
变量计数=0
函数addOne(){count=count+1}
//Date.now()返回一个大数字,表示
//自1970年1月1日以来已过的毫秒数
var now=Date.now()
//循环到Date.now()的时间为1000毫秒(1秒)或更长
//从我们开始循环开始的未来。在每个循环上,调用addOne
而(Date.now()-now<1000)addOne()
//最后是>=1000ms,所以让我们打印出总数
console.log(计数)
}
未定义
//在Firefox控制台上
测量速度()
4227461调试器评估代码:14:11
未定义
测量速度()
4103189调试器评估代码:14:11
未定义
//在Chrome控制台上
未定义
测量速度()
11193127
未定义
测量速度()
11153367
未定义
测量速度()
11159575

​***在1秒内完成的总任务甚至比不上chrome在1秒内完成的任务。

这段代码的意义是什么?它没有给你任何实质性的东西。也许
Date.now()
在FF上更昂贵,这只会真正影响到这个案例。这是不现实的,所以不管怎样。你可以更正日期。现在()在FF上更贵。它运行了许多计算,这是你们在1秒内可以看到的总数。你能在1秒内用手数到+1的次数;)?这就是为什么我认为它很重要的原因。问题在于你不是在衡量“我能在1秒内做多少”,而是具体地说“我能在1秒内调用
Date.now()
,执行减法和逻辑测试的次数”。所以,您的测试并不是一般地测量“工作量”。它只适用于这一特定情况。这一具体案例是非常不现实的,因此获得的数据基本上是无用的。为什么Date.now()在FF中很昂贵?