String concatenation: using += vs. using array push vs. unshift
JavaScript performance comparison
Info
Tests the performance difference of using two different ways of concatenating strings. The two TCs produce the same string result.
See http://jsperf.com/forloop-vs-reverse-while-loop-and-array-reverse/9 for array reverse vs custom loops.
See http://jsperf.com/array-push-reverse-vs-unshift-reverse for array push reverse vs. unshift reverse.
Preparation code
<script>
var length = 1500;
var html = [];
var str = "";
</script>
Test runner
Warning! For accurate results, please disable Firebug before running the tests. (Why?)
Java applet disabled.
| Test | Ops/sec | |
|---|---|---|
+= |
|
pending… |
push |
|
pending… |
unshift |
|
pending… |
push reverse |
|
pending… |
unshift reverse |
|
pending… |
fast push |
|
pending… |
fast push reverse |
|
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 FredCK
- Revision 2: published
- Revision 3: published
- Revision 5: published
- Revision 6: published by XP1
- Revision 7: published
- Revision 8: published
- Revision 9: published
0 comments