@@ -1116,7 +1116,7 @@ Comparison:
11161116 String#[0...n] ==: 427206.8 i/s - 4.79x slower
11171117```
11181118
1119- ##### ` Regexp#=== ` vs ` String#match ` vs ` String#=~ ` vs ` String#match? ` [ code ] ( code/string/===-vs-=~-vs-match.rb )
1119+ ##### ` Regexp#=== ` vs ` Regexp#match ` vs ` Regexp#match? ` vs ` String#match ` vs ` String#=~ ` vs ` String#match? ` [ code ] ( code/string/===-vs-=~-vs-match.rb )
11201120
11211121` String#match? ` and ` Regexp#match? ` are available on Ruby 2.4 or later.
11221122ActiveSupport [ provides] ( http://guides.rubyonrails.org/v5.1/active_support_core_extensions.html#match-questionmark )
@@ -1132,19 +1132,22 @@ improvement.
11321132
11331133```
11341134$ ruby -v code/string/===-vs-=~-vs-match.rb
1135- ruby 2.4.3p205 (2017-12-14 revision 61247) [x86_64-darwin17]
1136-
1135+ ruby 2.4.1p111 (2017-03-22 revision 58053) [x86_64-darwin16]
11371136Calculating -------------------------------------
1138- String#match? 6.284M (± 5.6%) i/s - 31.324M in 5.001471s
1139- String#=~ 2.581M (± 4.7%) i/s - 12.977M in 5.038887s
1140- Regexp#=== 2.482M (± 4.1%) i/s - 12.397M in 5.002808s
1141- String#match 2.097M (± 4.3%) i/s - 10.592M in 5.060535s
1137+ Regexp#match? 6.994M (± 3.0%) i/s - 35.144M in 5.029647s
1138+ String#match? 6.909M (± 3.3%) i/s - 34.663M in 5.023177s
1139+ String#=~ 2.784M (± 5.2%) i/s - 13.996M in 5.043168s
1140+ Regexp#=== 2.702M (± 4.5%) i/s - 13.631M in 5.056215s
1141+ Regexp#match 2.607M (± 4.9%) i/s - 13.025M in 5.009071s
1142+ String#match 2.362M (± 5.7%) i/s - 11.817M in 5.020344s
11421143
11431144Comparison:
1144- String#match?: 6283591.8 i/s
1145- String#=~: 2581356.8 i/s - 2.43x slower
1146- Regexp#===: 2482379.7 i/s - 2.53x slower
1147- String#match: 2096984.3 i/s - 3.00x slower
1145+ Regexp#match?: 6994107.7 i/s
1146+ String#match?: 6909055.7 i/s - same-ish: difference falls within error
1147+ String#=~: 2783577.8 i/s - 2.51x slower
1148+ Regexp#===: 2702030.0 i/s - 2.59x slower
1149+ Regexp#match: 2607484.0 i/s - 2.68x slower
1150+ String#match: 2362314.8 i/s - 2.96x slower
11481151```
11491152
11501153See [ #59 ] ( https://github.com/JuanitoFatas/fast-ruby/pull/59 ) and [ #62 ] ( https://github.com/JuanitoFatas/fast-ruby/pull/62 ) for discussions.
0 commit comments