inline-filter-cost

JavaScript performance comparison

Test case created by Dmitriy Kubyshkin

Preparation code


      
      <script>
Benchmark.prototype.setup = function() {
  var input = [];
  var max = 10000;
  for (var i = 0; i < 1000; ++i) {
      input.push(Math.floor(Math.random() * max) - max / 2);
  }
  
  function run(tester) {
      return input.forEach(tester)
  }

};
</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
inline
run(function (num) {
  if (num % 2) {
    return 'odd';
  }
  if (num < 0) {
    return 'negative'
  }
  return 'positive';
});
pending…
IIFE
run(function (num) {
  return (function (num) {
    if (num % 2) {
      return 'odd';
    }
    if (num < 0) {
      return 'negative'
    }
    return 'positive';
  }(num));
});
pending…
Binding outside
var outer;
run(function (num) {
  return (outer || (outer = function (num) {
    if (num % 2) {
      return 'odd';
    }
    if (num < 0) {
      return 'negative'
    }
    return 'positive';
  }))(num);
});
pending…

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

0 Comments