Created
December 19, 2013 12:31
-
-
Save themasch/8038446 to your computer and use it in GitHub Desktop.
faster for me (v0.10.21)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function faster_concat(list) | |
{ | |
var len = 0; | |
var listLen = list.length; | |
var offset = 0; | |
if(listLen === 1) { | |
return list[0] | |
} | |
for(var i=0;i<listLen;i++) { | |
len += list[i].length | |
} | |
var buf = new Buffer(len) | |
for(i=0;i<listLen;i++) { | |
var src = list[i] | |
src.copy(buf, offset) | |
offset += src.length | |
} | |
return buf | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I've made the experience that references are faster in small loops,
and the
+=
op is not optimized in some older versions of V8, I think;So maybe something like this: