测试和比较 jQuery 插件的性能
那里有大量的 jQuery 插件,所以我想确保当我找到两个或更多做同样事情的插件时,我会选择最好的。
我通常将文件大小作为性能的第一个指标,但我想知道我还能做些什么来测试和比较这些插件的性能。
我可以使用 jsperf.com 吗?把我想比较的插件放在那里。结果是衡量绩效的良好指标吗?
还有其他建议吗?
谢谢。
There are a tonne of jQuery plugins out there and so I want to ensure that when I find two or more plugins that do the same thing, I choose the best.
I generally go for filesize as a first indicator of peformance, but I was wondering else I can do to test and compare performance of these plugins.
Could I use jsperf.com? Throw those plugins I want to compare in there. Would the results be a good indicator as to the performance?
Any other suggestions?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
为了测量性能等,有一个很棒的免费工具正在流通:DynaTrace Ajax 3 Edition (http://ajax .dynatrace.com/ajax/en/ )
在你的情况下,你必须查看 JavaScript 部分 http://ajax.dynatrace.com/ajax/en/content /c-javascript-dom-tracing.aspx
这使您能够测量特定方法的性能等等。我过去曾使用它来优化 IE7 中运行的大型下拉菜单。这很有帮助!
For measuring performance and so on there's a great free tool in circulation: DynaTrace Ajax 3 Edition ( http://ajax.dynatrace.com/ajax/en/ )
In your case you have to look at the JavaScript part http://ajax.dynatrace.com/ajax/en/content/c-javascript-dom-tracing.aspx
Which gives you the ability of measuring performance of specific methods and so on. I've used it in the past to optimize a huge mega drop down menu running in IE7. It helped a lot!
文件大小并不是运行时性能的良好指标。如果您非常了解 javascript,您可以查看代码并对其编写得如何形成意见,但我不认为文件大小可以很好地衡量运行时性能。
如果性能对您来说真的很重要,那么做出有意义的决定的唯一方法就是衡量您关心的确切操作。 jsPerf 是一个非常有用的工具,用于在完成任务的两种不同方式之间进行性能比较。但是,在设计性能测试时您必须非常小心,以便您所测量的东西确实是正确的,并且 jsPerf 只能测量某些类型的东西。
更具体的建议将取决于特定的插件以及您最关心的它执行的操作类型。
作为参考,jQuery 有时可能是编写代码最快、最方便的方法,但对于速度真正重要的代码部分来说,通常不是最快的执行代码。例如,
document.getElementById("test").value = "foo"
比$("#test").val("foo")
快 5-7 倍>如下所示:http://jsperf.com/jquery-vs-plain-javascript。Filesize is not a good indicator of runtime performance. If you know javascript very well, you could look at the code and form an opinion of how well written it is, but I wouldn't expect filesize to be a good measure of runtime performance.
If performance really matters to you, then the only way to make a meaningful decision is to measure the exact operations that you care about. jsPerf is one very useful tool for setting up a performance comparison between two different ways of accomplishing a task. But, you have to be very careful when designing performance tests so that what you are measuring is really the right thing and jsPerf can only measure some types of things.
More specific advice would depend upon the specific plug-in and what types of operations it does that you care the most about.
For reference, jQuery may sometimes be the fastest and most convenient way to write code, but often isn't the fastest executing code for sections of code where speed really matters. For example,
document.getElementById("test").value = "foo"
is 5-7x faster than$("#test").val("foo")
as illustrated here: http://jsperf.com/jquery-vs-plain-javascript.一般来说,除了查看代码和自己测试之外,最好的性能指标是使用它的人数以及您读到的有关它的评论和评论。除非文件大小非常大,否则影响不大。
只需阅读其他人所说的内容、文档中有关已知问题的内容并做出有根据的猜测。
Generally the best indicator of performance, aside from looking through the code and testing it yourself, is the number of people using it along with the comments and reviews you read about it. File size is of little consequence unless it's extreme.
Just read what others have said, what the documentation says about known issues and make an educated guess.
注册 Sauce Labs,它可以让您测试最著名的浏览器/操作系统组合,并查看插件在每个您关心的浏览器。
(免费帐户每月可让您进行 45 分钟的测试。)
Sign up for Sauce Labs, which lets you test the most prominent browser/OS combinations, and see how the plugins perform in every browser you care about.
(A free account gives you 45 minutes of testing per month.)