String vs Array concat
JavaScript performance comparison
Info
A test case to see if concatenating an array instead of a string for an inflate library would perform better, based on this post: http://my.opera.com/emoller/blog/2011/05/01/javascript-performance
Preparation code
<script>
Benchmark.prototype.setup = function() {
var precompiled = 'apple';
while (precompiled.length < 100) {
var offs = precompiled.length - 5;
for (var i = offs; i < offs + 10; ++i) {
// calling charAt(i) on `precompiled` will
// flatten the string in most engines
precompiled += precompiled.charAt(i);
}
}
Array.prototype.fjoin=function(d){for(var a=0,c=this.length,b="";a<c;a++)b+=a<c-1?this[a]+d:this[a];return b};
};
</script>
Test runner
Warning! For accurate results, please disable Firebug before running the tests. (Why?)
Java applet disabled.
| Test | Ops/sec | |
|---|---|---|
String |
|
pending… |
String w/o flattening |
|
pending… |
fjoin |
|
pending… |
join |
|
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 Corey Schram
- Revision 2: published and last updated
- Revision 9: published
- Revision 10: published
- Revision 11: published
- Revision 12: published
- Revision 13: published
- Revision 14: published
- Revision 15: published
- Revision 16: published by greg
- Revision 17: published
- Revision 18: published
0 comments
Comment form temporarily disabled.