Boolean vs Int in Javascript

后端 未结 4 2013
独厮守ぢ
独厮守ぢ 2020-12-31 03:05

I always assumed that booleans were more efficient than ints at storing an on/off value - considering that\'s their reason for existence. I recently decided to check if this

4条回答
  •  一个人的身影
    2020-12-31 03:37

    your test was a bit off due to the definition of "function" and "var" and the call for the function. The cost to define function and variables and calling them will differ from engine to engine. I modified your tests, try to re-run with your browsers (note that IE was off because the first run was weird but consecutive runs were as expected where bool is fastest): http://jsperf.com/bool-vs-int-2/4

提交回复
热议问题