Nab
JavaScript performance comparison
Info
Demonstrating the performance hit caused by nested functions.
Preparation code
<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js">
</script>
<script>
function a() {
for (var i = 0; i < 10; i++) {
$("body").append("<div>a" + i + "</div>");
}
}
function b() {
var j = "";
for (var i = 0; i < 10; i++) {
j += "<div>a" + i + "</div>";
}
$("#d1").append(j);
}
</script>
Preparation code output
Test runner
Warning! For accurate results, please disable Firebug before running the tests. (Why?)
Java applet disabled.
| Test | Ops/sec | |
|---|---|---|
Optimized (No Nesting) |
|
pending… |
Nested Function |
|
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 3: published by gdsf
- Revision 4: published
- Revision 5: published by gdsf
- Revision 6: published
- Revision 7: published
- Revision 9: published
- Revision 10: published
- Revision 13: published
- Revision 14: published
- Revision 15: published
- Revision 16: published
- Revision 17: published
- Revision 18: published
- Revision 19: published
- Revision 20: published
- Revision 21: published
- Revision 22: published
- Revision 23: published
- Revision 24: published by max jooher
0 comments