Between (min/max)

JavaScript performance comparison

Test case created by Maciej

Preparation code


      
      <script>
Benchmark.prototype.setup = function() {
  function maxmin(val, min, max) {
    if (val > min) {
      if (val < max) {
        return val;
      } else return max;
    } else return min
  }
  
  function maxmin2(val, min, max) {
    return (Math.min(max, Math.max(min, val)));
  }
  function maxmin3(val, min, max){
    return (val > min) ? ((val < max) ? val : max) : min;
  }

};
</script>

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in CCBot 2.0.0 / Other 0.0.0
Test Ops/sec
minified
maxmin3(-800, 0, 1000);
maxmin3(200, -100, 1000);
maxmin3(1800, 0, 1000);
pending…
Without Math
maxmin(-800, 0, 1000);
maxmin(200, -100, 1000);
maxmin(1800, 0, 1000);
pending…
Using Math
maxmin2(-800, 0, 1000);
maxmin2(200, -100, 1000);
maxmin2(1800, 0, 1000);
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