that's a nice article about some real-world benchmarking. I wish more people did things like this. If you'd like a short tutorial, you can look here: http://on-ruby.blogspot.com/2008/12/benchmarking-makes-it-better.html On Wed, Jun 17, 2009 at 11:06 AM, Joshua Ball<chezball / gmail.com> wrote: > A friend recently sent me this article: > http://blog.metasploit.com/2009/03/blog-post.html > > In particular, note the perf difference of += vs << : > > framework3 $ time ruby -e 'a = "A"; 100000.times { a << "A" }' >> >> real 0m*0.338s* >> user 0m*0.312s* >> sys 0m0.024s >> >> framework3 $ time ruby -e 'a = "A"; 100000.times { a += "A" }' >> >> real 0m*15.462s* >> user 0m*15.321s* >> sys 0m0.068s > > > Also note: > > *Before you run off and change every instance of += to << in your ruby code*, >> it's important to note that the two don't perform the same operation. >> Because ruby does assignment by reference, the latter overwrites any >> variables that point to the one you're operating on while the former leaves >> any references untouched. >> >> >> framework3 $ irb >> >> a = "A" >> => "A" >> >> b = a >> => "A" >> >> a << "B" >> => "AB" >> >> b >> => "AB" > >>> c = "C" >> => "C" >> >> d = c >> => "C" >> >> c += "D" >> => "CD" >> >> d >> => "C" >> > > > > Thought I would pass it along... > -- thanks, -pate ------------------------- Don't judge those who choose to sin differently than you do http://on-ruby.blogspot.com http://eldersjournal.blogspot.com