如何衡量脚本执行和*解析*时间? [英] How to measures script execution and *parsing* time?

查看:151
本文介绍了如何衡量脚本执行和*解析*时间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

据我所知,脚本是在javascript中同步下载和执行的。
因此,如果我们编写以下代码:

As far as I know, scripts are downloaded and executed synchronously in javascript. Hence if we write the following code:

<script type='text/javascript'>console.time('core')</script>
<script type='text/javascript' src="guicore.js"></script>
<script type='text/javascript'>console.timeEnd('core')</script>

我们将在控制台的总时间内看到下载,解析和执行js。
我们如何排除解析时间?只需添加类似的文件,但所有代码都已注释掉。或多或少,这种技术应该有效。

we'll see in console total time for download, parse and execute js. How we can exclude parsing time? Just add similar file, but with all code commented out. More or less, this technique should work.

问题是这不起作用=)

我对该代码进行了优化,将执行时间从90ms减少到25ms,但Chrome的时间约为100±10ms,Firefox的时间约为160±15ms。

I optimized that code, reduce execution time from 90ms to 25ms, but see the same ~100±10ms time for Chrome and ~160±15ms for Firefox.

好的,我知道我可以使用探查器,但问题是:如何正确测量js解析时间以及我测量了什么。 Research.reverse-engineering非常有趣,但也许有人深入了解这个领域。

Ok, I know I could use profiler, but the question is: "how to measure js parsing time correctly" and what did I measured btw. Research.reverse-engineering is very fun, but maybe there's someone who knows that field in depth.

推荐答案

打开Chrome并打开开发人员工具,转到时间轴选项卡。如果按下录制按钮(填充圆圈,左下角)然后重新加载页面,它将为您提供相当详细的时间线,分解为特定类型的活动(发送请求,解析,评估),时间缩短到微秒。

Open up Chrome and open the developer tools, the go to the "Timeline" tab. If you press the record button (filled in circle, bottom left) then reload the page it'll give you a fairly detailed timeline, broken down into specific types of activity (Send Request, Parse, Evaluate), timed down to the microsecond.

这篇关于如何衡量脚本执行和*解析*时间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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