4 ms·
Turns out the comprehension is faster on my setup: http://jsperf.com/don-t-use-coffeescript http://jsperf.com/don-t-use-coffeescript
by mischanix 13y ago
Turns out the comprehension is faster on my setup:
http://jsperf.com/don-t-use-coffeescript http://jsperf.com/don-t-use-coffeescript
- Groxx 13y agoOn a lot of setups, going by the graph there. Firefox nightly produces an interesting test run: http://cl.ly/image/2s0p1Y3E2Z0C http://cl.ly/image/2s0p1Y3E2Z0C not really sure why that happens.
- rmrfrmrf 13y agoI was going to say... I thought one of the major selling points of CoffeeScript was that it outputs JavaScript that is highly optimized for JS interpreters.
- Kerrick 13y agoYep, the Comprehension is faster in all the environments I tested: Chrome 28.0.1500.71 on OS X 10.8.4 (map is 54% slower) Safari 6.0.5 on OS X 10.8.4 (map is 28% slower) Firefox 23.0 on OS X 10.8.4 (map is 62% slower)* Opera 12.16 on OS X 10.8.4 (map is 72% slower) IE 10.0 on Windows 7 [via VirtualBox] (map is 42% slower) And testing the same via a node.js benchmark it says the fastest is comprehension. https://gist.github.com/Kerrick/cff3d1212c82bc804712 https://gist.github.com/Kerrick/cff3d1212c82bc804712 * Every time I load the JSPerf page on Firefox, the first run the two tests are on par, and the second (and following) runs I get map being much slower. I have to wonder if the JS engine begins optimizing the comprehension version at some point.
- city41 13y agoFunction calls in JavaScript runtimes (including V8) are quite slow. Array.map/filter/forEach will always be slower than a for loop doing the same thing. I write a lot of games and game related things in JavaScript, and this is actually a major reason why I now use CoffeeScript. Nice clean comprehension syntax and better performance.
- jwmerrill 13y agoArray.map/filter/forEach aren't just slow because of function call overhead. They have different semantics than the for loop that you'd typically write (and that Coffeescript generates), because they support things like arrays with non-incremental keys. See the reference implementation at [1]. [1] https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map#compatibility https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe...
- deleted 13y ago[deleted]
- L8D 13y agoCan you run a test with the code in the article? I even said: "And that's still not ideal. We should be able to do: [code]". I don't ever advise using map, but you can't setup your own for loop in coffeescript. Actually, in the code shown, map isn't used at all. Just .filter and .forEach. Here is my version: http://jsperf.com/no-coffeescript-orig http://jsperf.com/no-coffeescript-orig The 'manual' is what I would write myself.