[nodejs] Array reads faster than Buffer reads ???

2012-10-03 Thread NodeNinja
Doing some tests on windows with node v0.8.11 var buf = new Buffer(1000); 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 '

Re: [nodejs] Array reads faster than Buffer reads ???

2012-10-03 Thread Ben Noordhuis
On Thu, Oct 4, 2012 at 1:37 AM, NodeNinja wrote: > Doing some tests on windows with node v0.8.11 > > var buf = new Buffer(1000); > buf.fill(0xFF); > > var len = buf.length; > var a; > var start = new Date(); > for(var b = 0 ; b < len; b++){ > a = bu

Re: [nodejs] Array reads faster than Buffer reads ???

2012-10-03 Thread NodeNinja
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 ex

Re: [nodejs] Array reads faster than Buffer reads ???

2012-10-03 Thread Ben Noordhuis
On Thu, Oct 4, 2012 at 1:51 AM, NodeNinja 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 s

Re: [nodejs] Array reads faster than Buffer reads ???

2012-10-03 Thread NodeNinja
On Thursday, October 4, 2012 5:44:16 AM UTC+5:30, Ben Noordhuis wrote: > > They won't, they're there mostly for convenience*. > Now that's an* eye opener* Ben! I hope that line finds its way to the documentation. Many thanks!! -- Job Board: http://jobs.nodejs.org/ Posting guidelines: https:

Re: [nodejs] Array reads faster than Buffer reads ???

2012-10-04 Thread Jimb Esser
If you want *really* fast buffer access for larger integer types and float types, you can set up a native module that calls SetIndexedPropertiesToExternalArrayData a few times on your Buffer and gives you a native indexed view into the buffer for whatever primitive type you want to read (much,

Re: [nodejs] Array reads faster than Buffer reads ???

2012-10-04 Thread Dan Milon
Curious, shouldn't V8 be able to inline the readUInt8 function call, or there's more than that? On Thu, Oct 4, 2012 at 1:43 AM, Ben Noordhuis wrote: > On Thu, Oct 4, 2012 at 1:37 AM, NodeNinja wrote: > > Doing some tests on windows with node v0.8.11 > > -

Re: [nodejs] Array reads faster than Buffer reads ???

2012-10-04 Thread NodeNinja
On Thursday, October 4, 2012 9:49:20 PM UTC+5:30, Jimb Esser wrote: > > If you want *really* fast buffer access for larger integer types and float > types, you can set up a native module that > calls SetIndexedPropertiesToExternalArrayData a few times on your Buffer > and gives you a native in

Re: [nodejs] Array reads faster than Buffer reads ???

2012-10-04 Thread NodeNinja
On Friday, October 5, 2012 1:58:17 AM UTC+5:30, Dan Milon wrote: > > Curious, shouldn't V8 be able to inline the readUInt8 function call, or > there's more than that? > > That's what even I was thinking about if all the buf.read*() and the buf.write*() functions are much slower than the indexed

Re: [nodejs] Array reads faster than Buffer reads ???

2012-10-04 Thread Ben Noordhuis
On Thu, Oct 4, 2012 at 6:19 PM, Jimb Esser wrote: > If you want *really* fast buffer access for larger integer types and float > types, you can set up a native module that calls > SetIndexedPropertiesToExternalArrayData a few times on your Buffer and gives > you a native indexed view into the buff

Re: [nodejs] Array reads faster than Buffer reads ???

2012-10-04 Thread Ben Noordhuis
On Fri, Oct 5, 2012 at 1:08 AM, NodeNinja wrote: > On Friday, October 5, 2012 1:58:17 AM UTC+5:30, Dan Milon wrote: >> Curious, shouldn't V8 be able to inline the readUInt8 function call, or >> there's more than that? >> > That's what even I was thinking about if all the buf.read*() and the > buf.

Re: [nodejs] Array reads faster than Buffer reads ???

2012-10-04 Thread Jimb Esser
Ah, yeah, it does now! We wrote our module back on node 0.4, which, I think, did not have typed arrays. That being said, it seems TypedArrays do not support un-aligned views (e.g. if you're reading a stream and want to read a F64 at byte offset 3, it throws an exception), as well they shouldn

Re: [nodejs] Array reads faster than Buffer reads ???

2012-10-05 Thread NodeNinja
On Friday, October 5, 2012 8:00:45 AM UTC+5:30, Ben Noordhuis wrote: You don't have to drop down to C++ for that, node.js supports typed arrays[1]. I probably should have mentioned that in my other post. :-) Thats some good news! :) Besides, they're pure JS functions while buf[i] is an intr

Re: [nodejs] Array reads faster than Buffer reads ???

2012-10-05 Thread NodeNinja
On Friday, October 5, 2012 12:29:00 PM UTC+5:30, Jimb Esser wrote: > > The gist of it is just to take a Buffer, for each type you want to read > (say, e.g, 32-bit ints), make a number of views equal to the possible byte > offsets (e.g. 4) and then do a read with the right offset from the right

Re: [nodejs] Array reads faster than Buffer reads ???

2012-10-05 Thread Ben Noordhuis
On Fri, Oct 5, 2012 at 8:59 AM, Jimb Esser wrote: > Ah, yeah, it does now! We wrote our module back on node 0.4, which, I > think, did not have typed arrays. That being said, it seems TypedArrays do > not support un-aligned views (e.g. if you're reading a stream and want to > read a F64 at byte

Re: [nodejs] Array reads faster than Buffer reads ???

2012-10-05 Thread Ben Noordhuis
On Fri, Oct 5, 2012 at 1:03 PM, NodeNinja wrote: > Is there a comprehensive list of what functions are intrinsic and which > functions are in pure JS? Basically anything that's not an operator is a function. That's also true for JS built-ins like Array.prototype.sort(), etc. -- Job Board: http: