On Thu, Oct 4, 2012 at 1:51 AM, NodeNinja <[email protected]> wrote: > > > On Thursday, October 4, 2012 5:13:30 AM UTC+5:30, Ben Noordhuis wrote: >> >> >> 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. > > > Excellent suggestion Ben: > New results are exciting :) > > Buffer reads 21 ms > Array reads 29 ms > > What about the other functions like readUIntXX and readIntXX ,I may not be > able to use indexing in those cases. > Or will they be as fast as using indexing?
They won't, they're there mostly for convenience*. If you need to read in e.g. a little-endian short, do this: v = buf[i] | (buf[i + 1] << 8); Same but big-endian: v = (buf[i] << 8) | buf[i + 1]; * Except for the float and double functions - reading and writing IEEE 754 floating point numbers is *hard*. -- 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
