custom vs builtin max (v2)

Revision 2 of this benchmark created on


Description

Native max vs my max

Preparation HTML

<script>
function mymax(a, b, c) {
  if (a > b) {
    if (a > c) return a;
    return c;
  }
  if (b > c) return b;
  return c;
}

function ternary(a, b, c) {
  return (a > b) ? a > c ? a : c : b > c ? b : c;
}

function maximax (a, b, c) { return Math.max(Math.max(a,b),c); }

function test(f, n) {
  var s = 0, x = n / 2;
  for (var i = 0; i < n; ++i)
    for (var j = 0; j < n; ++j)
      s += f(i, j, x);
}

var n = 6

</script>

Test runner

Ready to run.

Testing in
TestOps/sec
mymax
test(mymax, n);
ready
Math.max
test(Math.max, n);
ready
maximax
test(maximax, n);
ready
ternary
test(ternary, n);
ready

Revisions

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