Noop vs function prototype

JavaScript performance comparison

Revision 4 of this test case created by Cezary Daniel Nowak

Preparation code

<script>
window.testArr = [];
</script>
      
<script>
Benchmark.prototype.setup = function() {
  var NOOP1 = Function();
  var NOOP2 = function() {};
  var NOOP3 = new Function;
  var NOOP4 = Function.prototype;
  var NOOP5 = function() {return;};
  var NOOP6 = function() {return null;};
  function NOOP7() {}
  
  window.testArr.length = 0; // I hope, GC will not kill our results

};
</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
Function()
window.testArr.push(NOOP1());
window.testArr.push(NOOP1.call(window));
window.testArr.push(NOOP1(Math.random()));
pending…
function() {}
window.testArr.push(NOOP2());
window.testArr.push(NOOP2.call(window));
window.testArr.push(NOOP2(Math.random()));
pending…
new Function
window.testArr.push(NOOP3());
window.testArr.push(NOOP3.call(window));
window.testArr.push(NOOP3(Math.random()));
pending…
Function.prototype
window.testArr.push(NOOP4());
window.testArr.push(NOOP4.call(window));
window.testArr.push(NOOP4(Math.random()));
pending…
function() {return;}
window.testArr.push(NOOP5());
window.testArr.push(NOOP5.call(window));
window.testArr.push(NOOP5(Math.random()));
pending…
function() {return null;}
window.testArr.push(NOOP6());
window.testArr.push(NOOP6.call(window));
window.testArr.push(NOOP6(Math.random()));
pending…
function noop() {}
window.testArr.push(NOOP7());
window.testArr.push(NOOP7.call(window));
window.testArr.push(NOOP7(Math.random()));
pending…

Compare results of other browsers

Revisions

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

0 Comments