如何对JavaScript代码进行基准测试? [英] How can I benchmark JavaScript code?

查看:135
本文介绍了如何对JavaScript代码进行基准测试?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有帮助我对JavaScript代码进行基准测试的软件包?我不是指Firebug和这样的工具。

Is there a package that helps me benchmark JavaScript code? I'm not referring to Firebug and such tools.

我需要比较我实现的2个不同的JavaScript函数。我非常熟悉Perl的Benchmark( Benchmark.pm )模块,我正在寻找类似的东西JavaScript。

I need to compare 2 different JavaScript functions that I have implemented. I'm very familiar with Perl's Benchmark (Benchmark.pm) module and I'm looking for something similar in JavaScript.

重点是对JavaScript代码进行基准测试是否过分了?我可以只计算一次运行时间吗?

Has the emphasis on benchmarking JavaScript code gone overboard? Can I get away with timing just one run of the functions?

推荐答案

只需对每个函数进行多次迭代。一次迭代可能是不够的,但是(取决于你的函数有多复杂),接近100或甚至1000次迭代应该可以完成这项工作。

Firebug还有一个分析器,如果你想看看你的功能的哪些部分正在减慢它。

Firebug also has a profiler if you want to see which parts of your function are slowing it down.

编辑对于未来的读者,推荐JSPerf的以下答案应该是正确答案。我会删除我的,但我不能,因为它已被OP选中。基准测试不仅仅是运行多次迭代,而且JSPerf会为您完成这项工作。

To future readers, the below answer recommending JSPerf should be the correct answer. I would delete mine, but I can't because it has been selected by the OP. There is much more to benchmarking than just running many iterations, and JSPerf takes care of that for you.

这篇关于如何对JavaScript代码进行基准测试?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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