jsPerf.app is an online JavaScript performance benchmark test runner & jsperf.com mirror. It is a complete rewrite in homage to the once excellent jsperf.com now with hopefully a more modern & maintainable codebase.
jsperf.com URLs are mirrored at the same path, e.g:
https://jsperf.com/negative-modulo/2
Can be accessed at:
https://jsperf.app/negative-modulo/2
Compare for loop performance.
The previous version of this test set the global array
variable used in the tests as window.array
. This test instead declare this variable as var array
. This has a significant effect on the results of the tests. The previous version showed the CoffeeScript-generated code to be slower than the lodash code. This version of the test shows that the CoffeeScript-generated code is the fastest.
The reason for this is that accessing array
if the VM has to resolve it to window.array
is slower than accessing array
if it has been defined with var
. So the CoffeeScript-generated code would be at a disadvantage relative to lodash since lodash grabs a reference to array
once whereas the CoffeeScript code refers to it on each iteration.
<script src="https://rawgithub.com/lodash/lodash/2.2.1/dist/lodash.min.js">
</script>
<script src="https://code.jquery.com/jquery-2.0.3.min.js">
</script>
<script>
jQuery.quickEach = (function() {
return function(arr, c) {
var i = -1,
el, len = arr.length;
try {
while (++i < len && (el = arr[i]) && c.call(el, i, el) !== false);
} catch (e) {
throw e;
}
};
}());
</script>
var _i, _results;
var array = (function() {
_results = [];
for (_i = 1; _i <= 1000; _i++) {
_results.push(_i);
}
return _results;
}).apply(this);
Ready to run.
Test | Ops/sec | |
---|---|---|
CoffeeScript for loop |
| ready |
_.each / Lodash |
| ready |
$.each |
| ready |
array.forEach |
| ready |
$.quickEach |
| ready |
for with scope |
| ready |
real coffee for loop |
| ready |
Latest coffee version |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.