onload vs DOMContentLoaded

Benchmark created on


Preparation HTML

<script>
  var fn = function() {console.log(2*2)};
  function r(f){/in/.test(document.readyState)?setTimeout('r('+f+')',9):f()}
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
load event
window.addEventListener('load', fn);
ready
onload
window.onload = fn;
ready
ready
r(fn);
ready
DOMContentLoaded
document.addEventListener('DOMContentLoaded',fn);
ready

Revisions

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