-
-
Save eregon/998ecc6c4e18ee1dca8c71b23eeb934c 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/ips' | |
# require 'benchmark-memory' | |
arr = %w[foobar foobaz bazquux hello world just making this array longer] | |
REGEXP = /o/ | |
def select_match(arr) | |
arr.select { |e| e.match?(REGEXP) } | |
end | |
def grep(arr) | |
arr.grep(REGEXP) | |
# arr.select { |e| REGEXP === e } | |
end | |
Benchmark.ips do |x| | |
x.iterations = 2 | |
x.report("select.match?") { select_match(arr) } | |
x.report("grep") { grep(arr) } | |
x.compare! | |
end | |
# puts "********* MEMORY *********" | |
# | |
# Benchmark.memory do |x| | |
# x.report("select.match?") { select_match(arr) } | |
# x.report("grep") { grep(arr) } | |
# x.compare! | |
# end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment