Angular.js Backbone.js或具有更好的性能 [英] Angular.js Backbone.js or which has better performance

查看:116
本文介绍了Angular.js Backbone.js或具有更好的性能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是一名Web开发人员,我开始大量开发Web应用程序,但我不知道要使用什么框架。我正在考虑Angular.js,但是我也考虑过Backbone.js。对于你来说,最好的框架是什么?或至少在两个
之间进行比较以查看表现。

I am a web developer and I'm starting to develop a web application on a large scale, but I'm not sure what framework to use. I was thinking of Angular.js, but I also considered Backbone.js. For you, what would be the best framework? or at least have a comparison between the two to see the performance.

推荐答案

这里的任何人声称一个解决方案是比其他人更快或更慢,对于这些图书馆或框架(或一般来说都是一般的测试)并不太了解,或者是骗子。

Anybody here claiming that one solution is faster or slower than other either doesn't know much about any of these libraries or frameworks (or perf testing in general) or is a liar.

性能非常棘手由于影响到这么多变量而要测量的特征。只要命名几个:

Performance is a very tricky characteristic to measure because of so many variables that affect it. Just to name few:


  • 测试/基准代码的质量

  • 库/框架代码

  • 应用程序类型

  • 应用程序代码的质量

  • 浏览器使用

  • 客户端hw

  • 客户端上同时运行的其他进程hw

  • 互联网连接的质量和速度

  • 服务器加载和服务器性能

  • ,列表继续...

  • quality of the test/benchmark code
  • quality of the library/framework code
  • type of application
  • quality of the application code
  • browser used
  • client hw
  • other processes running at the same time on the client hw
  • quality and speed of the internet connection
  • server load and server performance
  • and the list goes on and on...

但更重要的是,你的表现是什么意思?性能是一个非常广泛的术语,涵盖太多的东西,包括:

but more importantly, what exactly do you mean by performance? performance is a very broad term that covers too many things, including:


  • 引导应用程序所需的时间

  • 响应用户操作所需的时间

  • 资源利用率(cpu / memory / network)

  • 图书馆/框架/应用程序代码

  • 垃圾收集器友善性

  • 再次列表继续...

  • time it takes to bootstrap the app
  • time it takes to respond to a user action
  • resource utilization (cpu/memory/network)
  • performance of dom manipulation done by the library/framework/app code
  • garbage collector friendliness
  • and again the list goes on and on...

回答您的问题的最佳方法是创建一个很好代表您打算构建的应用程序的应用程序,并实现它与竞争的图书馆/框架。然后写一个质量的基准,在稳定的环境中比较他们的头脑。

The best way to answer your question is to create an application that is well representative of the application you are intending to build and implement it with the competing libraries/frameworks. Then write a quality benchark that will compare them head to head in a stable environment.

这显然是一项非常费力的任务,只有一个有很大危险的人才会承担

This is obviously a very laborious task and only someone with a lot at stake would undertake it.

然而,这个问题有一个不同的解决方案:了解您正在使用的框架/库:

There is however a different solution to this problem: understand the framework/library you are using and specifically:


  • 了解框架/库内部使用的核心流和算法。而您通常不应该关心,当您遇到严重问题时,了解应用程序的执行情况,将使您能够识别和修复perf问题。

  • 检查性能是否为库/框架作者在

  • 中检查框架/库是否可以帮助您识别性能问题并解决问题。

对于Backbone和AngularJS之间的实际比较,您正在比较两种非常不同的解决方案。

As for the actual comparison between Backbone and AngularJS, you are comparing two very different solutions.

骨干不会为您做任何dom操作您的应用程序的速度将主要取决于您可以做多少操控(这是您的专业知识吗?)。

Backbone doesn't do any dom manipulation for you, so the speed of your app will mostly depend on how well can you do dom manipulation (is this your expertise?).

AngularJS为您和我们的大多数操纵在这方面有很多专业知识,所以除非你真的很好,否则你会很难匹配我们。

AngularJS does most of the dom manipulation for you and we have a ton of expertise in this area, so unless you are really good, you'll have a hard time matching us.

其次,骨干模型突变观察是基于事件,模型包装和人造的使用吸气器和设置器。由于缺少事件合并(这可能是最新骨干版本中可能存在的一种解决方法),这不仅可以非常低效,而且使用人工吸引器和设置器也会影响浏览器中的JIT编译器。

Secondly, backbone's model mutation observation is based on events, model wrappers and use of artificial getters and setters. Not only that this can be very inefficient due to lack of event coalescence (there might be a workaround for this in latest backbone versions), but the use of artificial getters and setters also interferes with the JIT compiler in your browser.

Misko写了一个长发 Angular如何进行神奇的模型突变观察。所以我不会在这里重复一遍。但是基本上AngularJS应用程序的性能与应用程序当前视图中使用的绑定的数量和复杂程度直接相关。考虑到这一点,您可以轻松预测Angular的表现。更好的是,使用诸如AngularJS Batarang扩展Chrome的工具,我们允许您轻松地对应用程序进行调整,并了解页面上的哪些绑定速度很慢,这样您就可以专注于修复真正重要的代码部分。

Misko wrote up a long post on how Angular does its magical model mutation observation. So I'm not going to repeat it here. But basically the performance of an AngularJS app is directly related to the number and complexity of bindings used in the current view of the application. With this in mind, you can easily predict Angular's performance. Even better is that with tools like AngularJS Batarang extension for Chrome, we allow you to easily instrument your application and understand which bindings on the page are slow and this allows you to focus on fixing the parts of your code that really matter.

我要总结说,没有图书馆或框架将是您所有用例的最佳解决方案,因此您应该了解更多有关构建应用程序的工具当它真的重要时,决定哪一个是给定用例的最好的。我打赌的是,对于大部分要编写的应用程序,如果您切换框架或库,性能不会明显改变。所以我会更加重视其他因素,如生产力,易用性,可测试性,社区和文档,然后再担心性能。

I'm going to conclude by saying that no library or framework will be the best solution for all of your use cases, so you should learn more about the tools you build your apps with and when it really matters, decide which one is the best for a given use case. My bet is that for most of the apps you are going to write, performance is not going to noticeably change if you switch framework or library. So I would put more weight on other factors like productivity, easy of use, testability, community and documentation before I would worry about performance.

最后一件事:通常会误导,但请查看这些,并带上一些盐。

And the very last thing: benchmarks are often misleading, but check out these ones and take them with a grain of salt.

  • Backbone + Ember: http://jsfiddle.net/jashkenas/CGSd5/
  • AngularJS: http://jsfiddle.net/mhevery/vYknU/23/

这篇关于Angular.js Backbone.js或具有更好的性能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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