Operator Overloading vs Branches

Benchmark created on


Preparation HTML

<script>
  function piOverloadA(cap)
  {
      return 4/function y(x){return x<cap?x*x/y(x+1)+2*x-1:1}(1);
  }
  function piOverloadB(cap, branch)
  {
      return 'blah';
  }
  function piBranch(cap, branch)
  {
      if(branch)
      {
          return 'blah';
      }
      else
      {
          return 4/function y(x){return x<cap?x*x/y(x+1)+2*x-1:1}(1);
      }
  }
  function piControlA(cap)
  {
      return 'blah'
  }
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
Overload
if (Math.round(Math.random()) === 1) {
  piOverloadA(23);
} else {
  piOverloadB(23, true);
}
ready
Branch
if (Math.round(Math.random()) === 1) {
  piBranch(23, true);
} else {
  piBranch(23, false);
}
ready

Revisions

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