javascript - Socket.IO Performance Oddities -
i've been running few tests figure out fastest way send specific data using latest socket.io version (v1.4.5).
i tried passing object, string, uint8array , buffer. i'm excluding time generate formatted data.
var d = date.now(); var obj = {"q":"-dgn,pqusy","u":{"gm5sp":[1109,1001],"t9sck":[2026],"hpcm8":[1407,841],"dnb7s":[1285,478],"pv7dt":[2043,986,31]}}; var objstr = json.stringify(obj); var objuint8 = new uint8array(objstr.length); for(var = 0 ; < objstr.length; i++) objuint8[i] = objstr[i].charcodeat(i); var objbuffer = new buffer(objuint8); for(var = 0 ; < 20000; i++){ if(num === 0) socket.emit('a',obj); if(num === 1) socket.emit('a',objstr); if(num === 2) socket.emit('a',objuint8); if(num === 3) socket.emit('a',objbuffer); } console.log(date.now() - d);
results:
object: 244ms
string: 126ms
uint8array: 1292ms
buffer: 212ms
why uint8array slow? isn't similar nodejs buffer? shouldn't buffer faster string?
Comments
Post a Comment