delayed onload
JavaScript performance comparison
Preparation code
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>
</title>
<script type='text/javascript'>
window.q = [];
window.$ = function(f) {
q.push(f)
}
</script>
</head>
<body>
<div>
<script>
$(function() {
console.log("wallop");
});
</script>
<nav>
<ol>
<li>
<a href="##">1</a>
<script>
$(function() {
console.log("wallop");
});
</script>
</li>
<li>
<a href="##">2</a>
<script>
$(function() {
console.log("wallop");
});
</script>
</li>
<li>
<a href="##">3</a>
<script>
$(function() {
console.log("wallop");
});
</script>
</li>
<li>
<a href="##">4</a>
<script>
$(function() {
console.log("wallop");
});
</script>
</li>
<li>
<a href="##">5</a>
<script>
$(function() {
console.log("wallop");
});
</script>
</li>
<li>
<a href="##">6</a>
<script>
$(function() {
console.log("wallop");
});
</script>
</li>
<li>
<a href="##">7</a>
<script>
$(function() {
console.log("wallop");
});
</script>
</li>
<li>
<a href="##">8</a>
<script>
$(function() {
console.log("wallop");
});
</script>
</li>
<li>
<a href="##">9</a>
<script>
$(function() {
console.log("wallop");
});
</script>
</li>
</ol>
</nav>
<script>
$(function() {
$("a").click(function(ev) {
ev.preventDefault();
console.log($(this).text());
});
});
</script>
</div>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js">
</script>
</body>
</html>
Preparation code output
Test runner
Warning! For accurate results, please disable Firebug before running the tests. (Why?)
Java applet disabled.
| Test | Ops/sec | |
|---|---|---|
with onload |
|
pending… |
without |
|
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. Here’s a list of current revisions for this page:
- Revision 1: published by Phil Parsons
- Revision 2: published
2 comments
What the hell is with the IE9 results :/
With the console active, results are more normal (2,000 or less). I don't know how to confirm this, but maybe IE's Dead Code Elimination is preventing the console.log from executing. Creating a function that does nothing.