Skip to content

Instantly share code, notes, and snippets.

@corpix
Created October 23, 2012 11:36
Show Gist options
  • Select an option

  • Save corpix/3938308 to your computer and use it in GitHub Desktop.

Select an option

Save corpix/3938308 to your computer and use it in GitHub Desktop.
Buffer.concat(list) vs str += buf.toString()
var chunks = 10000;
var buf;
buf = new Buffer(4069);
buf.fill('a', 0, 4069);
(function(){
var arr = [],
concated,
j = 0;
console.time('buffer.concat');
for( ; j <= 10000; j++){
arr.push(buf);
}
concated = Buffer.concat(arr);
console.timeEnd('buffer.concat');
})();
(function(){
var concated = '',
j = 0;
console.time('string.concat');
for( ; j <= 10000; j++){
concated += buf.toString();
}
console.timeEnd('string.concat');
})();
~
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment