Max inside For-loop vs Max with Map

JavaScript performance comparison

Test case created

Preparation code

Benchmark.prototype.setup = function() {
    var a = [];
    var s = "";
    var max;
    for (var i = 0; i < 10000; ++i) {
        s += "a";
    var b = (si) { return si.length; });

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);
Max with Map
max = Math.max.apply(Math, b);

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

Compare results of other browsers


Comment form temporarily disabled.

Add a comment