addEventListener

JavaScript performance comparison

Revision 3 of this test case created by Erick Ribeiro

Preparation code

<button id="button1">
  Click here
</button>
      
<script>
Benchmark.prototype.setup = function() {
  function test2() {
    var x = 1;
    var y = 2;
    alert(x + y);
  }

};

Benchmark.prototype.teardown = function() {
  document.getElementById("button1").onclick = function(){};

};
</script>

Preparation code output

<button id="button1"> Click here </button>

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 inside addEventListener
document.getElementById("button1").addEventListener("click", function() {
  var x = 1;
  var y = 2;
  alert(x + y);
}, false);
pending…
function outside addEventListener
document.getElementById("button1").addEventListener("click", test2, false);
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