-
-
Save agrimm/6138788 to your computer and use it in GitHub Desktop.
Fork of delete-tr.rb run in 2013, comparing Rubinius against MRI
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'benchmark' | |
TIMES = 1000 | |
s = "a long string" * 1000 | |
Benchmark.bmbm do |x| | |
x.report("delete") do | |
TIMES.times { s.delete(" ") } | |
end | |
x.report("tr") do | |
TIMES.times { s.tr(" ", "") } | |
end | |
x.report("gsub with regexp") do | |
TIMES.times { s.gsub(/ /, "") } | |
end | |
x.report("gsub with string") do | |
TIMES.times { s.gsub(" ", "") } | |
end | |
end | |
# Under MRI 2.0.0-p247 | |
# ruby 2.0.0p247 (2013-06-27 revision 41674) [x86_64-darwin11.4.2] | |
# Rehearsal ---------------------------------------------------- | |
# delete 0.030000 0.010000 0.040000 ( 0.032588) | |
# tr 0.030000 0.000000 0.030000 ( 0.029961) | |
# gsub with regexp 0.670000 0.000000 0.670000 ( 0.670667) | |
# gsub with string 0.670000 0.000000 0.670000 ( 0.673313) | |
# ------------------------------------------- total: 1.410000sec | |
# | |
# user system total real | |
# delete 0.040000 0.000000 0.040000 ( 0.032628) | |
# tr 0.030000 0.000000 0.030000 ( 0.032721) | |
# gsub with regexp 0.690000 0.000000 0.690000 ( 0.697010) | |
# gsub with string 0.670000 0.000000 0.670000 ( 0.671953) | |
# Under rbx | |
# rubinius 2.0.0.n204 (1.9.3 97416082 2013-07-23 JI) [x86_64-apple-darwin11.4.2] | |
# Rehearsal ---------------------------------------------------- | |
# delete 0.223000 0.003194 0.226194 ( 0.189438) | |
# tr 0.153779 0.000554 0.154333 ( 0.154239) | |
# gsub with regexp 1.289229 0.012082 1.301311 ( 1.008253) | |
# gsub with string 0.806960 0.006720 0.813680 ( 0.809855) | |
# ------------------------------------------- total: 2.495518sec | |
# | |
# user system total real | |
# delete 0.149678 0.000271 0.149949 ( 0.149861) | |
# tr 0.149242 0.000271 0.149513 ( 0.149397) | |
# gsub with regexp 0.798716 0.006516 0.805232 ( 0.801440) | |
# gsub with string 0.814010 0.007074 0.821084 ( 0.817623) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment