Created
July 9, 2016 08:00
-
-
Save davydovanton/d5d1c888b5ce7bb3ca41a1bd49a67aa5 to your computer and use it in GitHub Desktop.
Benchmark: regex interpolation
This file contains hidden or 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' | |
GITHUB_COM = %r{https?://(?:www\.)?github\.com}i | |
Benchmark.ips do |x| | |
x.report('with o') { %r{\A#{GITHUB_COM}/([^/]+)/?\z}o } | |
x.report('without o') { %r{\A#{GITHUB_COM}/([^/]+)/?\z} } | |
x.compare! | |
end | |
# Warming up -------------------------------------- | |
# with o 137.742k i/100ms | |
# without o 7.493k i/100ms | |
# Calculating ------------------------------------- | |
# with o 10.680M (± 5.8%) i/s - 53.306M | |
# without o 80.892k (± 2.6%) i/s - 404.622k | |
# | |
# Comparison: | |
# with o: 10679946.9 i/s | |
# without o: 80891.8 i/s - 132.03x slower |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment