console.time显示运行相同功能的不同时间 [英] console.time shows different time running the same function

查看:138
本文介绍了console.time显示运行相同功能的不同时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用console.time来显示功能的时间。但是我发现它显示了相同功能的不同运行时间。



我简化了功能,如下所示:

  const findIP =(res)=> {
let arr = []
arr = res.split(',')
}
console.time('1')
findIP('1, 2,3,4,5,6,7,8,9,0')
console.timeEnd('1')
console.time('2')
findIP(' 1,2,3,4,5,6,7,8,9,0')
console.timeEnd('2')

两者之间的时间差非常大。





我尝试运行几次。而且仍然要花费不同的时间。



解决方案

在以下链接中引用答案:


如果多次缩短运行,则V8引擎具有一个JIT编译器,该编译器将优化该代码段,以便在下一次运行时更快。 //stackoverflow.com/a/54601440\">https://stackoverflow.com/a/54601440


I use console.time to show the time of the function. But I found that it shows different running time of the same function.

I have simplified my function as below:

const findIP = (res) => {
    let arr = []
    arr = res.split(',')
}
console.time('1')
findIP('1,2,3,4,5,6,7,8,9,0')
console.timeEnd('1')
console.time('2')
findIP('1,2,3,4,5,6,7,8,9,0')
console.timeEnd('2')

The time difference between the two is very large.

I have tried to run several times. And it still cost different time.

解决方案

To quote the answer in the the following link:

If you run shorten multiple times, the V8 engine has a JIT compiler that will optimize that piece of code so it runs faster the next time.

https://stackoverflow.com/a/54601440

这篇关于console.time显示运行相同功能的不同时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆