3 ms·
In case anyone cares, here's a jsfiddle for KnockoutJS: http://jsfiddle.net/2pLk3/5/ http://jsfiddle.net/2pLk3/5/ I was curious how it would stack up - the ans
by Lazare 15y ago
In case anyone cares, here's a jsfiddle for KnockoutJS:
http://jsfiddle.net/2pLk3/5/ http://jsfiddle.net/2pLk3/5/
I was curious how it would stack up - the answer seems to be "pretty well, actually". Of course, all the normal warnings about synthetic benchmarks apply. :)
Edit: I'm updated the JSFiddle to attempt to properly clean up the Knockout bindings. Probably. As I said, I'm pretty new to Knockout still, and may well have made a mistake.
- jashkenas 15y agoLooks great -- but you need to clean up the knockout bindings when clicking a button again. After a few clicks, it gets slower and slower... Also affects which button you click first.
- krosaen 15y agoThanks for this - I always wonder why knockout doesn't get more attention on hacker news, it's really great and seems to meet the same needs as ember. Plus, their tutorials are awesome: http://learn.knockoutjs.com http://learn.knockoutjs.com
- schinckel 15y agoYou are not actually using ko.computed objects in your fiddle. My take on it: http://jsfiddle.net/HusVw/1/ http://jsfiddle.net/HusVw/1/ And guess what, it's _much_ slower. (And I'm a happy KO user).
- krosaen 15y agoThere's some discussion on the ko google groups about this : https://groups.google.com/forum/?fromgroups#!topic/knockoutjs/xb0oS00ndlE https://groups.google.com/forum/?fromgroups#!topic/knockoutj... you are right, the correct version is perhaps slightly faster than the ember, but way slower than the backbone example. However, by leveraging an optimized ko.computed implementation http://mbest.github.com/knockout-deferred-updates/ http://mbest.github.com/knockout-deferred-updates/ the results are much more impressive. http://jsfiddle.net/2pLk3/10/ http://jsfiddle.net/2pLk3/10/
- Lazare 15y agoI'm don't agree that that the version with unused intermediate computed observables is the only correct version (or that there even is only one correct version). Avoiding the use of intermediate computeds makes the Knockout version roughly as fast as Backbone for this specific benchmark, and more closely replicates the functionality of the Backbone example. That sounds like the correct version to me.
- Lazare 15y agoFeh. As multiple people have kindly pointed out to me, I had a silly typo in my code and was accidentally clobbering the ko.computed function. The updated jsfiddle is here: http://jsfiddle.net/2pLk3/18/ http://jsfiddle.net/2pLk3/18/ Embarrassing. :)