String concat + single append vs multiple append
JavaScript performance comparison
Preparation code
<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<style type="text/css">
.container { height: 50px; width:100%; overflow:hidden}
</style>
<div class="container"></div>
<script>
var cnt = $('.container');
var str = '<div class="sample">test</div>' +
'<div class="sample2">test</div>' +
'<div class="sample3">test</div>' +
'<div class="sample4">test</div>' +
'<div class="sample5">test</div>';
</script>
Preparation code output
Test runner
Warning! For accurate results, please disable Firebug before running the tests. (Why?)
Java applet disabled.
| Test | Ops/sec | |
|---|---|---|
String concat + single append |
|
pending… |
Multiple append |
|
pending… |
String concat + single append on cached element |
|
pending… |
String concat + multiple append on cached element |
|
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 Addy Osmani
- Revision 2: published
- Revision 3: published
- Revision 4: published
- Revision 6: published by Andrée
0 comments