On Thu, Oct 4, 2012 at 1:37 AM, NodeNinja <[email protected]> wrote: > Doing some tests on windows with node v0.8.11 > -------------------------------------------- > var buf = new Buffer(10000000); > buf.fill(0xFF); > > var len = buf.length; > var a; > var start = new Date(); > for(var b = 0 ; b < len; b++){ > a = buf.readUInt8(b); > } > var end = new Date(); > > console.log('Buffer reads ' + (end - start) + ' ms'); // Prints 81ms > > ------------------------------------------------ > > var arr = []; > var len = 10000000; > for(b = 0 ; b < len; b++){ > arr[b] = 0xFF; > } > var len = arr.length; > console.log(len); > start = new Date(); > for(b = 0 ; b < len; b++){ > a = arr[b]; > } > end = new Date(); > > console.log('Array reads ' + (end - start) + ' ms'); // Prints 29ms > > And I always thought that buffers would be faster than arrays in node.js ? > :( > Am I doing something wrong ??
Don't use buf.readUInt8(), it's only there for the sake of parity with the other .readUInt*() functions. Replace it with `a = buf[b]` and you'll see a 4-5x speed-up. -- Job Board: http://jobs.nodejs.org/ Posting guidelines: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines You received this message because you are subscribed to the Google Groups "nodejs" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/nodejs?hl=en?hl=en
