-
-
Save yfeldblum/5abb30cfaa89413ee55a to your computer and use it in GitHub Desktop.
Benchmark making regexps.
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' | |
STRING = "string" | |
def sm ; STRING ; end | |
def sl ; "string" ; end | |
Benchmark.bmbm do |x| | |
t = 10_000_000 | |
x.report("string-constant") { t.times { STRING } } | |
x.report("string-literal") { t.times { "string" } } | |
x.report("regexp-literal") { t.times { /string/ } } | |
x.report("regexp-inter-string-constant") { t.times { /#{STRING}/ } } | |
x.report("regexp-inter-string-constant-m") { t.times { /#{sm}/ } } | |
x.report("regexp-inter-string-literal") { t.times { /#{"string"}/ } } | |
x.report("regexp-inter-string-literal-m") { t.times { /#{sl}/ } } | |
end |
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
Rehearsal ------------------------------------------------------------------ | |
string-constant 1.710000 0.140000 1.850000 ( 1.070000) | |
string-literal 1.070000 0.020000 1.090000 ( 1.030000) | |
regexp-literal 0.670000 0.000000 0.670000 ( 0.648000) | |
regexp-inter-string-constant 7.600000 0.040000 7.640000 ( 7.516000) | |
regexp-inter-string-constant-m 8.260000 0.030000 8.290000 ( 8.221000) | |
regexp-inter-string-literal 0.680000 0.000000 0.680000 ( 0.672000) | |
regexp-inter-string-literal-m 8.360000 0.020000 8.380000 ( 8.408000) | |
-------------------------------------------------------- total: 28.600000sec | |
user system total real | |
string-constant 0.640000 0.000000 0.640000 ( 0.649000) | |
string-literal 0.920000 0.000000 0.920000 ( 0.912000) | |
regexp-literal 0.650000 0.000000 0.650000 ( 0.647000) | |
regexp-inter-string-constant 7.580000 0.020000 7.600000 ( 7.619000) | |
regexp-inter-string-constant-m 8.120000 0.030000 8.150000 ( 8.152000) | |
regexp-inter-string-literal 0.680000 0.000000 0.680000 ( 0.682000) | |
regexp-inter-string-literal-m 8.130000 0.010000 8.140000 ( 8.140000) |
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
Rehearsal ------------------------------------------------------------------ | |
string-constant 0.780000 0.000000 0.780000 ( 0.772820) | |
string-literal 1.740000 0.000000 1.740000 ( 1.745241) | |
regexp-literal 0.740000 0.000000 0.740000 ( 0.745060) | |
regexp-inter-string-constant 37.140000 0.000000 37.140000 ( 37.178668) | |
regexp-inter-string-constant-m 38.300000 0.030000 38.330000 ( 38.419389) | |
regexp-inter-string-literal 0.740000 0.000000 0.740000 ( 0.743964) | |
regexp-inter-string-literal-m 40.250000 0.010000 40.260000 ( 40.296169) | |
------------------------------------------------------- total: 119.730000sec | |
user system total real | |
string-constant 0.720000 0.000000 0.720000 ( 0.724254) | |
string-literal 1.700000 0.000000 1.700000 ( 1.700508) | |
regexp-literal 0.700000 0.000000 0.700000 ( 0.701369) | |
regexp-inter-string-constant 37.100000 0.000000 37.100000 ( 37.135231) | |
regexp-inter-string-constant-m 38.320000 0.000000 38.320000 ( 38.400480) | |
regexp-inter-string-literal 0.700000 0.000000 0.700000 ( 0.702838) | |
regexp-inter-string-literal-m 40.000000 0.000000 40.000000 ( 40.038571) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment