Created
October 12, 2009 02:16
-
-
Save dominikh/208067 to your computer and use it in GitHub Desktop.
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 = 1_000_000 | |
Benchmark.bmbm() do |x| | |
# note: this regexp will only be built once for all iterations | |
x.report("literal regexp") do | |
TIMES.times { /regexp/ } | |
end | |
x.report("new regexp from regexp") do | |
TIMES.times { Regexp.new(/regexp/) } | |
end | |
x.report("new regexp from string") do | |
TIMES.times { Regexp.new("regexp") } | |
end | |
end | |
# Rehearsal ---------------------------------------------------------- | |
# literal regexp 0.180000 0.000000 0.180000 ( 0.188121) | |
# new regexp from regexp 6.690000 0.010000 6.700000 ( 6.705013) | |
# new regexp from string 7.670000 0.010000 7.680000 ( 7.672104) | |
# ------------------------------------------------ total: 14.560000sec | |
# user system total real | |
# literal regexp 0.280000 0.000000 0.280000 ( 0.277063) | |
# new regexp from regexp 6.830000 0.020000 6.850000 ( 6.847951) | |
# new regexp from string 7.760000 0.010000 7.770000 ( 7.767159) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment