Min, Max, or conditionals

JavaScript performance comparison

Test case created

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
    var min = Math.min,
        max = Math.max,
        a = [];
};
</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
a = [];
for (var x = 0; x < 100; x++) {
  a[x] = [];
  for (var y = 0; y < 100; y++) {
    a[x][y] = max(x, y);
  }
}
pending…
Min
a = [];
for (var x = 0; x < 100; x++) {
  a[x] = [];
  for (var y = 0; y < 100; y++) {
    a[x][y] = min(x, y);
  }
}
pending…
Condition-max
a = [];
for (var x = 0; x < 100; x++) {
  a[x] = [];
  for (var y = 0; y < 100; y++) {
    a[x][y] = x > y ? x : y;
  }
}
pending…
Condition-min
a = [];
for (var x = 0; x < 100; x++) {
  a[x] = [];
  for (var y = 0; y < 100; y++) {
    a[x][y] = x < y ? x : y;
  }
}
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