str = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabbb"
1.9.3p0 :009 > Benchmark.measure { 1_000_000.times { str.sub(/b+\z/, "") } }
=> 1.410000 0.010000 1.420000 ( 1.410129)
1.9.3p0 :010 > Benchmark.measure { 1_000_000.times { str.sub(/b+\z/, "") } }
=> 1.400000 0.000000 1.400000 ( 1.405524)
1.9.3p0 :011 > Benchmark.measure { 1_000_000.times { str.sub(/b+\z/, "") } }
=> 1.400000 0.000000 1.400000 ( 1.396972)
1.9.3p0 :012 > Benchmark.measure { 1_000_000.times { str.gsub(/b+\z/, "") } }
=> 3.130000 0.020000 3.150000 ( 3.148422)
1.9.3p0 :013 > Benchmark.measure { 1_000_000.times { str.gsub(/b+\z/, "") } }
=> 3.140000 0.030000 3.170000 ( 3.168520)
1.9.3p0 :014 > Benchmark.measure { 1_000_000.times { str.gsub(/b+\z/, "") } }
=> 3.130000 0.020000 3.150000 ( 3.149087)
1.9.3p0 :015 > Benchmark.measure { 1_000_000.times { str.sub(/b*\z/, "") } }
=> 2.530000 0.000000 2.530000 ( 2.540740)
1.9.3p0 :016 > Benchmark.measure { 1_000_000.times { str.sub(/b*\z/, "") } }
=> 2.540000 0.000000 2.540000 ( 2.533296)
1.9.3p0 :017 > Benchmark.measure { 1_000_000.times { str.sub(/b*\z/, "") } }
=> 2.570000 0.000000 2.570000 ( 2.571964)