max using .map vs .reduce

JavaScript performance comparison

Test case created

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
    var array = [[1, 5], [4, 7], [3, 8], [2, 3], [12, 4], [6, 6], [4, 1], [3, 2], [8, 14], [1, 5], [4, 7], [3, 8], [2, 3], [12, 4], [6, 6], [4, 1], [3, 2], [8, 14], [1, 5], [4, 7], [3, 8], [2, 3], [12, 4], [6, 6], [4, 1], [3, 2], [8, 14], [1, 5], [4, 7], [3, 8], [2, 3], [12, 4], [6, 6], [4, 1], [3, 2], [8, 14]];
   
    var result;
};
</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
.map
result = Math.max.apply(Math, array.map(function(arr) {
    return arr[0];
}));
pending…
.reduce
result = array.reduce(function(max, arr) {
    return Math.max(max, arr[0]);
}, -Infinity);
pending…
.reduce without Math.max
result = array.reduce(function(max, arr) {
    return max >= arr[0] ? max : arr[0];
}, -Infinity);
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