clip-perf

JavaScript performance comparison

Test case created by Josh

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
    function clip1(value, min, max) {
      return Math.min(Math.max(value, min), max);
    }
   
    function clip2(value, min, max) {
      return value < min ? min : (value > max ? max : value);
    }
   
    function clip3(value, min, max) {
      if (value < min) return min;
      else if (value > max) return max;
      else return value;
    }
};
</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
Math
clip1(50, 1, 100);
clip1(-50, 1, 100);
clip1(150, 1, 100);
pending…
ternary
clip2(50, 1, 100);
clip2(-50, 1, 100);
clip2(150, 1, 100);
pending…
if
clip3(50, 1, 100);
clip3(-50, 1, 100);
clip3(150, 1, 100);
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