Skip to content

Instantly share code, notes, and snippets.

@dominikh
Created October 12, 2009 01:20
Show Gist options
  • Save dominikh/208032 to your computer and use it in GitHub Desktop.
Save dominikh/208032 to your computer and use it in GitHub Desktop.
require "benchmark"
n = 1_000_000
s = "a string to split"
d1 = / /
d2 = " "
Benchmark.bmbm do |x|
x.report("Regexp") do
n.times do
s.split(d1)
end
end
x.report("String") do
n.times do
s.split(d2)
end
end
end
# Rehearsal ------------------------------------------
# Regexp 7.720000 0.060000 7.780000 ( 7.794611)
# String 4.280000 0.020000 4.300000 ( 4.413137)
# -------------------------------- total: 12.080000sec
# user system total real
# Regexp 8.530000 0.160000 8.690000 ( 8.805900)
# String 4.350000 0.070000 4.420000 ( 4.482934)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment