Created
January 13, 2016 16:37
-
-
Save cschneid/0bcf9498f60665c65bf5 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' | |
CALLER = caller | |
REGEX = /(\/app\/(controllers|models|views)\/.+)/.freeze | |
def constant_regex | |
CALLER.each { |x| x.match(REGEX) } | |
end | |
def literal_regex | |
CALLER.each { |x| x.match(/(\/app\/(controllers|models|views)\/.+)/) } | |
end | |
N = 10_000_000 | |
Benchmark.bm do |x| | |
x.report("constant") { N.times { constant_regex } } | |
x.report("literal") { N.times { literal_regex } } | |
end | |
# user system total real | |
# constant 0.940000 0.000000 0.940000 ( 0.943816) | |
# literal 0.960000 0.000000 0.960000 ( 0.968538) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment