Sum Array Test

JavaScript performance comparison

Test case created

Info

Very simple test shows that the function reduce is much slower than a simple loop.

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
    myLargeArray = [];
    for (var i = 0, n = 1000; i < n; i++)
       myLargeArray.push(123);
};
</script>

Test runner

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

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
SumArray
var total = 0;
for (var i = 0; i < myLargeArray .length; i++) {
    total += myLargeArray [i];
}
pending…
SumArrayAgain
myLargeArray.reduce(function(a, b) {
    return a + b;
});
pending…

Compare results of other browsers

Revisions

You can edit these tests or add even more tests to this page by appending /edit to the URL. Here’s a list of current revisions for this page:

0 comments

Add a comment