la domanda è già risposto, ma quando ho visto la prima volta ho pensato di NodeJS Buffer. Ma è molto più lento del +, quindi è probabile che nulla possa essere più veloce di + in concetanation di stringhe.
testato con il seguente codice:
function a(){
var s = "hello";
var p = "world";
s = s + p;
return s;
}
function b(){
var s = new Buffer("hello");
var p = new Buffer("world");
s = Buffer.concat([s,p]);
return s;
}
var times = 100000;
var t1 = new Date();
for(var i = 0; i < times; i++){
a();
}
var t2 = new Date();
console.log("Normal took: " + (t2-t1) + " ms.");
for (var i = 0; i < times; i++){
b();
}
var t3 = new Date();
console.log("Buffer took: " + (t3-t2) + " ms.");
uscita:
Normal took: 4 ms.
Buffer took: 458 ms.
Anche se ciò fosse vero (la concatenazione di stringhe è molto lenta), il codice dipende da esso in modo così pesante che è importante? – WTK