I don't think there's anything wrong with how you're using streams. Your version trades performance for a more consistent memory file, and theirs does the opposite. The nice thing about your implementation is that it can handle a much larger source file, and can start working before the whole file has been pulled down.
If you wanted to improve performance while still streaming, I'd look at figuring out how many of the pipeline steps you could combine, as each stage in the pipeline is necessarily going to add at least a little overhead. It may also be that combining them allows you to eliminate some work (maybe at the cost of using more memory), e.g. eliminating some of the conversions between Buffers and strings. F On Sat, Apr 5, 2014 at 10:01 PM, Dan Schmidt <[email protected]>wrote: > So, I'm trying to use streams more and better understand how to use them > properly. > > There was this little contest over at Treehouse to write an app that would > count the words in a text file after being filtered from a certain set of > words in another file. > > Myself and one other person chose to write our apps in node. > > I wrote mine using streams and they wrote theirs without. I have used the > time command to compare the two. Mine is consistently about 5 times slower. > > Link to mine: https://gist.github.com/DanSchmidt/10000777 > Link to their's: https://gist.github.com/pleary/9967501#file-waldo-js > > I could understand if some of my transform and filtering logic was perhaps > less performant than another's, but 5 times slower seems to suggest I'm > probably doing something wrong with the streams. > > Any help would be appreciated, thanks. > > -- > -- > 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 > > --- > You received this message because you are subscribed to the Google Groups > "nodejs" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > For more options, visit https://groups.google.com/d/optout. > -- -- 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 --- You received this message because you are subscribed to the Google Groups "nodejs" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/d/optout.
