From: "Berger, Daniel" Date: 2005-03-20T11:37:47+09:00 Subject: Re: RCR 296: Destructive methods return self > -----Original Message----- > From: Nikolai Weibull > [mailto:mailing-lists.ruby-talk@rawuncut.elitemail.org] > Sent: Saturday, March 19, 2005 6:12 PM > To: ruby-talk ML > Subject: Re: RCR 296: Destructive methods return self > > A comment on your benchmark: doesn't it make more sense to do > the tests on new strings each time? Yeah, you're right. I just used string literals instead of variables. With that I got: C:\eclipse\workspace\ruby-foo\benchmarks>ruby bang.rb user system total real capitalize 2.103000 0.000000 2.103000 ( 2.132000) capitalize! 1.762000 0.000000 1.762000 ( 1.793000) chomp 1.853000 0.010000 1.863000 ( 2.072000) chomp! 1.622000 0.000000 1.622000 ( 1.652000) delete 5.578000 0.000000 5.578000 ( 5.807000) delete! 5.348000 0.000000 5.348000 ( 5.527000) downcase 2.093000 0.000000 2.093000 ( 2.113000) downcase! 1.722000 0.000000 1.722000 ( 1.812000) gsub 4.237000 0.000000 4.237000 ( 4.346000) gsub! 4.125000 0.020000 4.145000 ( 4.315000) lstrip 1.993000 0.010000 2.003000 ( 2.043000) lstrip! 1.703000 0.000000 1.703000 ( 1.852000) next 1.892000 0.010000 1.902000 ( 2.153000) next! 2.474000 0.000000 2.474000 ( 2.543000) reverse 1.943000 0.020000 1.963000 ( 1.972000) reverse! 1.522000 0.000000 1.522000 ( 1.723000) rstrip 1.943000 0.010000 1.953000 ( 2.112000) rstrip! 1.652000 0.000000 1.652000 ( 1.662000) slice 2.213000 0.010000 2.223000 ( 2.233000) slice! 4.487000 0.040000 4.527000 ( 4.716000) strip 2.053000 0.010000 2.063000 ( 2.103000) strip! 1.632000 0.000000 1.632000 ( 1.752000) sub 4.086000 0.020000 4.106000 ( 4.165000) sub! 3.645000 0.010000 3.655000 ( 3.815000) swapcase 2.374000 0.000000 2.374000 ( 2.433000) swapcase! 1.982000 0.010000 1.992000 ( 2.103000) tr 3.626000 0.000000 3.626000 ( 3.694000) tr 3.114000 0.000000 3.114000 ( 3.295000) tr_s 3.605000 0.010000 3.615000 ( 3.965000) tr_s! 3.195000 0.010000 3.205000 ( 3.724000) upcase 2.263000 0.010000 2.273000 ( 2.353000) upcase! 1.913000 0.010000 1.923000 ( 1.993000) Definitely an improvement. So, I guess that still leaves the question of what qualifies as "noticeably slower". ;) Regards, Dan