Underscore With(out) Native Array Extras

JavaScript performance comparison

Test case created by Jeremy Ashkenas

Preparation code

<script src="https://raw.github.com/documentcloud/underscore/master/underscore.js"></script>
<script>
window.new_ = _.noConflict();
</script>
<script src="https://raw.github.com/documentcloud/underscore/bf1bddd38d8ffefac152f85fe74fa80767868f84/underscore.js"></script>
<script>
window.old_ = _.noConflict();
</script>
<script>
Benchmark.prototype.setup = function() {
    var array = [];
    var identity = new_.identity;
    var i = 1000;
    while (i--) array.push(i);
   
};
</script>

Preparation code output

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
old each
old_.each(array, identity);
pending…
new each
new_.each(array, identity);
pending…
old map
old_.map(array, identity);
pending…
new map
new_.map(array, identity);
pending…
old reduce
old_.reduce(array, function(memo, num){ return memo + num; });
pending…
new reduce
new_.reduce(array, function(memo, num){ return memo + num; });
pending…
old filter
old_.filter(array, function(num){ return num % 2 == 0; });
pending…
new filter
new_.filter(array, function(num){ return num % 2 == 0; });
pending…
old every
old_.every(array, function(num){ return true; });
pending…
new every
new_.every(array, function(num){ return true; });
pending…
old some
old_.some(array, function(num){ return false; });
pending…
new some
new_.some(array, function(num){ return false; });
pending…

You can edit these tests or add even more tests to this page by appending /edit to the URL.

Compare results of other browsers

0 comments

Add a comment