SortEveryLoop

JavaScript performance comparison

Test case created

Info

Sorting on every loop or looping twice

Preparation code

<script>
  var arr = [3, 7, 7, 7, 7, 10, 10, 8, 5, 5, 5, 5, 20, 20, 1, 3, 7, 7, 7, 7, 10, 10, 8, 5, 5, 5, 5, 20, 20, 1, 3, 7, 7, 7, 7, 10, 10, 8, 5, 5, 5, 5, 20, 20, 1, 3, 7, 7, 7, 7, 10, 10, 8, 5, 5, 5, 5, 20, 20, 1, 3, 7, 7, 7, 7, 10, 10, 8, 5, 5, 5, 5, 20, 20, 1, 3, 7, 7, 7, 7, 10, 10, 8, 5, 5, 5, 5, 20, 20, 1, 3, 7, 7, 7, 7, 10, 10, 8, 5, 5, 5, 5, 20, 20, 1, 3, 7, 7, 7, 7, 10, 10, 8, 5, 5, 5, 5, 20, 20, 1, 3, 7, 7, 7, 7, 10, 10, 8, 5, 5, 5, 5, 20, 20, 1, 3, 7, 7, 7, 7, 10, 10, 8, 5, 5, 5, 5, 20, 20, 1, 3, 7, 7, 7, 7, 10, 10, 8, 5, 5, 5, 5, 20, 20, 1, 3, 7, 7, 7, 7, 10, 10, 8, 5, 5, 5, 5, 20, 20, 1, 3, 7, 7, 7, 7, 10, 10, 8, 5, 5, 5, 5, 20, 20, 1, 3, 7, 7, 7, 7, 10, 10, 8, 5, 5, 5, 5, 20, 20, 1, 3, 7, 7, 7, 7, 10, 10, 8, 5, 5, 5, 5, 20, 20, 1, 3, 7, 7, 7, 7, 10, 10, 8, 5, 5, 5, 5, 20, 20, 1, 3, 7, 7, 7, 7, 10, 10, 8, 5, 5, 5, 5, 20, 20, 1, 3, 7, 7, 7, 7, 10, 10, 8, 5, 5, 5, 5, 20, 20, 1, 3, 7, 7, 7, 7, 10, 10, 8, 5, 5, 5, 5, 20, 20, 1, 3, 7, 7, 7, 7, 10, 10, 8, 5, 5, 5, 5, 20, 20, 1, 3, 7, 7, 7, 7, 10, 10, 8, 5, 5, 5, 5, 20, 20, 1, 3, 7, 7, 7, 7, 10, 10, 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7, 10, 10, 8, 5, 5, 5, 5, 20, 20, 1, 3, 7, 7, 7, 7, 10, 10, 8, 5, 5, 5, 5, 20, 20, 1, 3, 7, 7, 7, 7, 10, 10, 8, 5, 5, 5, 5, 20, 20, 1, 3, 7, 7, 7, 7, 10, 10, 8, 5, 5, 5, 5, 20, 20, 1, 3, 7, 7, 7, 7, 10, 10, 8, 5, 5, 5, 5, 20, 20, 1, 3, 7, 7, 7, 7, 10, 10, 8, 5, 5, 5, 5, 20, 20, 1];
</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
sort every loop
function min_most_duplicate(arr) {
  var result = {},
      max = 0,
      res;

  arr = arr.slice(0); // make a copy of the array
  arr.sort(function(a, b) {
    return (a - b);
  }); // sort it numerically
  for (var i = 0, total = arr.length; i < total; ++i) {
    var val = arr[i],
        inc = (result[val] || 0) + 1;

    result[val] = inc;

    if (inc > max) {
      max = inc;
      res = val;
    }
  }

  return res;
}

min_most_duplicate(arr);
pending…
loop twice
var result = {},
    max = 0,
    res, key, min;
for (var i = 0, total = arr.length; i < total; ++i) {
  var val = arr[i],
      inc = (result[val] || 0) + 1;

  result[val] = inc;

  if (inc > max) {
    max = inc;
    res = val;
  }
}
for (var i in result) {
  if (result[i] === max) {
    key = parseInt(i, 10);
    min = min || key;
    console.log(min)
    if (min > key) {
      min = key;

    }
  }
}
res = min;
alert(res);
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