Max inside For-loop vs Max with Map

JavaScript performance comparison

Test case created

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
    var a = [];
    var s = "";
    var max;
    for (var i = 0; i < 10000; ++i) {
        a.push(s);
        s += "a";
    }
    var b = a.map(function (si) { return si.length; });
};
</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
Max inside For-loop
for (var i = 0; i < 10000; ++i) {
    max = Math.max(max, a[i].length);
}
pending…
Max with Map
max = Math.max.apply(Math, b);
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