Skip to content

Instantly share code, notes, and snippets.

@ugisozols
Created June 11, 2014 06:38
Show Gist options
  • Save ugisozols/6cb08668e7aaf5df7516 to your computer and use it in GitHub Desktop.
Save ugisozols/6cb08668e7aaf5df7516 to your computer and use it in GitHub Desktop.
Rehearsal ----------------------------------------------------
split/map/reject 0.060000 0.000000 0.060000 ( 0.064907)
scan with regex 0.030000 0.000000 0.030000 ( 0.024250)
------------------------------------------- total: 0.090000sec
user system total real
split/map/reject 0.070000 0.000000 0.070000 ( 0.068857)
scan with regex 0.020000 0.000000 0.020000 ( 0.023608)
require "benchmark"
str = "\n \t\tab 09:09 \t\t\n \t\tan 10:57 \t"
n = 10000
Benchmark.bmbm do |x|
x.report("split/map/reject") do
n.times do
str.split(/\t/).map(&:strip).reject(&:empty?)
end
end
x.report("scan with regex") do
n.times do
str.scan(/\d{2}:\d{2}/)
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment