简体   繁体   English

Google Closure Library的基准测试

[英]Benchmark for Google Closure Library

When I search for performance of Javascript libraries I get many sites showing the comparision of performance between the following popular libraries 当我搜索Javascript库的性能时,我得到了许多站点,显示了以下流行库之间的性能比较

  • jQuery (pretty slow) jQuery(很慢)
  • Prototype(very slow in IE) 原型(在IE中非常慢)
  • Dojo ( fastest when comes to DOM ) Dojo(来到DOM时最快)
  • ExtJs (average) ExtJs(平均值)
  • Micro JS( slow but OK ) Micro JS(慢但OK)

But in any of the benchmarks, Google Closure Library is NOT included. 但在任何基准测试中, Google Closure Library 都不包括在内。 Is it not like any other standard library for it is said that it is a procedural style library. 它是不是像任何其他标准库一样,据说它是一个程序式库。

I need some benchmarks on the performance of Closure library. 我需要一些关于Closure库性能的基准测试。 And would like an advice on "Is switching to Closure library good when using dojo at beginner stage and jQuery at some intermediate stage" 并且想要一个关于“在初学者阶段使用dojo并在某个中间阶段使用jQuery时切换到Closure库的建议”的建议

Google posts that it uses the closure library in all its apps like Gmail, etc... The performance is very good. 谷歌发布它在其所有应用程序(如Gmail等)中使用关闭库...性能非常好。 Is this because of the library ? 这是因为图书馆吗? Can an intermediate javaScript coder who can write OO code in JS use Closure library to very high level, or is it advisable to continue using DOJO. 可以在JS中编写OO代码的中间javaScript编码器是否可以将Closure库用于非常高的级别,或者建议继续使用DOJO。

On Closure Library 关闭图书馆

The Closure Library is pretty close to Dojo in style -- actually, when it was first developed, the authors took inspiration from Dojo. Closure Library非常接近Dojo的风格 - 实际上,当它最初开发时,作者从Dojo中获取灵感。

However, the speed and power of the Closure Library came from the Closure Compiler, which heavily optimizes a JavaScript program in order to remove all the bottlenecks (such as navigating chains of namespaces). 但是,Closure库的速度和功能来自Closure Compiler,它大大优化了JavaScript程序,以消除所有瓶颈(例如导航命名空间链)。

I personally don't like it a single bit as it detracts from the beauty of Dojo class-based constructs (simply to satisfy the compiler) and all those goog.kitchen.sink.getMeACupOfTeaSoICanRelax() long namespaces make writing (and reading) JavaScript programs a royal pain -- the fact that long namespaces are all optimized away by the compiler does not make it pretty (to me) to overuse them because you can . 我个人不喜欢它,因为它有损于基于Dojo类的构造的美丽(只是为了满足编译器)和所有那些goog.kitchen.sink.getMeACupOfTeaSoICanRelax()长命名空间使得编写(和阅读)JavaScript编程一个皇家的痛苦 - 长编辑器都被编译器优化掉的事实并没有让我(因为你可以 )过度使用它们。

In addition, its obsession with trying to make JavaScript programs look as much OOP as possible (perhaps because there are tons of Java programmers in Google) means over-reliance on OOP concepts like property getters and setters and the avoidance of many useful (and unique) JavaScript features like mixin's. 此外,它试图使JavaScript程序看起来尽可能多的OOP(也许是因为Google中有大量的Java程序员)意味着过度依赖OOP概念,如属性getter和setter以及避免许多有用的(和唯一的) )mixin的JavaScript功能。 If you are a Java programmer learning to program in JavaScript, you'll be right at home using the Closure Library. 如果您是一名学习使用JavaScript编程的Java程序员,那么您将使用Closure Library在家中。 That doesn't make it any bit elegant. 这并不会让它有点优雅。

It does, however, offer an industrial strength environment that is rock solid -- since Google has built HUGE sites with it. 然而,它确实提供了坚如磐石工业强度环境 - 因为Google已经用它构建了巨大的网站。 It is something that (in my personal opinion) is solid and works well, but looks ugly. 这是(在我个人看来)坚实而且运作良好的东西,但看起来很难看。

However, Dojo is rock solid as well, but more volatile since it is an open-source development project. 然而,Dojo也是坚如磐石的,但由于它是一个开源开发项目,因此更加不稳定。 You decide whether you'd like to switch. 您决定是否要切换。

On the Closure Compiler and Dojo 在Closure Compiler和Dojo上

Actually, you can use Dojo with the Closure Compiler in Advanced Mode also. 实际上,您也可以在高级模式下使用Dojo和Closure Compiler。 See this link for a description on how to do it. 有关如何操作的说明,请参阅此链接 Based on my own tests, a program compiled by the Closure Compiler is typically around 25% smaller than minified versions (due to dead-code elimination) and runs about 20-30% faster for simple pages and more for large pages. 根据我自己的测试,Closure Compiler编译的程序通常比缩小版本小25%(由于死码消除),对于简单页面运行速度提高约20-30%,对于大页面运行速度提高约20-30%。

On Speed of Libraries in General 论一般图书馆的速度

Other libraries all have their own characteristics and quirks, and each balance useability, flexibility and power with performance. 其他库都有自己的特点和怪癖,每个都平衡了可用性,灵活性和功能与性能。 For example, jQuery creates many many jQuery objects on the way and has a performance penalty, especially on older browsers. 例如,jQuery在途中创建了许多jQuery对象,并且性能下降,尤其是在旧版浏览器上。 However, modern browsers, esp. 但是,现代浏览器,尤其是 Google Chrome, actually does optimizations so that the performance hits of using jQuery is minimal. Google Chrome实际上进行了优化,因此使用jQuery的性能最低。

You actually need to ask yourself why you need JavaScript to run fast. 实际上你需要问问自己为什么需要JavaScript来快速运行。 Most modern browsers are already quite fast so that it is really not a very important consideration regarding choice of library. 大多数现代浏览器已经非常快,因此对于库的选择而言,它实际上并不是一个非常重要的考虑因素。 Better choose your library based on whether it suits you or not (and the task you're at hand) instead of whether it runs 10ms faster in a browser. 最好根据它是否适合您(以及您手头的任务)选择您的库,而不是在浏览器中运行速度快10ms。

If you are writing a web site for mobile devices, or writing an HTML5 game for instance, you may need to squeeze the last drop of performance (in games) and/or save as much resources as possible (in mobile). 如果您正在为移动设备编写网站,或者编写HTML5游戏,您可能需要挤压最后一滴性能(在游戏中)和/或尽可能多地节省资源(在移动设备中)。 In such cases, I find that using Dojo and then compiling with the Closure Compiler yields one of the best combinations for such scenarios. 在这种情况下,我发现使用Dojo然后使用Closure Compiler进行编译会产生这种情况的最佳组合之一。

Would be nice to back this up with some data. 用一些数据来支持这个很好。 There's lies, statistics and benchmarks. 有谎言,统计和基准。 You may for example ask yourself why framework x is slower then framework y. 例如,您可能会问自己为什么框架x比框架y慢。 In general though, benchmarks do not reflect real world scenario's, and end to be fun, but useless. 但总的来说,基准测试并不能反映现实世界的情景,最终会变得有趣,但却无用。 I've worked with jQuery for a few years now and I've not encountered situations where it's slow, or that it had any effect on the usability. 我已经使用jQuery几年了,我没有遇到过慢的情况,或者它对可用性有任何影响。

I your code is too slow and you need to optimize it. 我的代码太慢,你需要优化它。 Then you may benchmark, profile and debug the sweet jesus out of that code. 然后,您可以从该代码中对甜蜜耶稣进行基准测试,分析和调试。 Things like gmail are likely to have had that kind of treatment. 像gmail这样的东西可能会有这样的待遇。 So gmail is probably not fast because of closure, but fast because of intelligent programming. 因此,由于关闭,gmail可能并不快,但因为智能编程而快速。

If you're affraid of slow code, you might want to learn generic javascript optimization methods, and you'll be a happy camper with any framework. 如果你害怕代码慢,你可能想学习通用的javascript优化方法,并且你将成为一个快乐的任何框架的露营者。

edit: on closure Choosing closure might have several advantages when you're building big and complex: there are some nice bandwith optimization tools, tools for managing more complex applications. 编辑:关闭当你构建大而复杂的时候选择关闭可能有几个优点:有一些不错的带宽优化工具,用于管理更复杂的应用程序的工具。 There is a good guideline on how to write proper code, and tools to check that you followed these guidelines (closure linter, quite interesting). 有关如何编写正确代码的良好指导,以及检查您是否遵循这些指导原则的工具(封闭linter,非常有趣)。 There's a nice templating system (probably won't improve your performance per se) and dependency management stuff. 有一个很好的模板系统(可能不会提高你的性能本身)和依赖管理的东西。 If you wish to integrate these tools, or build upon it, I would say go for it, otherwise, you may rest easy and be happy with your choice for dojo. 如果你想整合这些工具,或者建立它,我会说它去吧,否则,你可以放松一下,并对你对道场的选择感到满意。

using dojo at beginner stage and jQuery at some intermediate stage 在初学者阶段使用dojo,在某个中间阶段使用jQuery

You've got that the wrong way around. 你有错误的方法。 Dojo is far more advanced than jQuery. Dojo比jQuery更先进。 jQuery itself is for beginners. jQuery本身适合初学者。

Can an intermediate javaScript coder who can write OO code in JS use Closure library to very high level, or is it advisable to continue using DOJO. 可以在JS中编写OO代码的中间javaScript编码器是否可以将Closure库用于非常高的级别,或者建议继续使用DOJO。

Either library will work. 这两个库都可以工作。 Spend a few hours playing with google closure and see how you find it. 花几个小时玩谷歌关闭,看看你是如何找到它的。 I doubt there's that much difference apart from general easy integration with google libraries like google charts. 我怀疑除了谷歌图书馆之类的谷歌图书馆的一般轻松整合之外还有那么大的差异。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM