@@ -786,28 +786,36 @@ Comparison:
786786 String#=~: 891124.1 i/s - 3.30x slower
787787```
788788
789- ##### ` String#match ` vs ` String#=~ ` [ code ] ( code/string/match -vs-=~.rb )
789+ ##### ` Regexp#=== ` vs ` String#match ` vs ` String#=~ ` [ code ] ( code/string/=== -vs-=~-vs-match .rb )
790790
791791> :warning : <br >
792792> Sometimes you can't replace ` match ` with ` =~ ` , <br >
793793> This is only useful for cases where you are checking <br >
794- > for a match and not using the resultant match object.
794+ > for a match and not using the resultant match object. <br >
795+ > :warning : <br >
796+ > ` Regexp#=== ` is also faster than ` String#match ` but you need to switch the order of arguments.
795797
796798```
797- $ ruby -v code/string/match -vs-=~.rb
799+ $ ruby -v code/string/=== -vs-=~-vs-match.rb .rb
798800ruby 2.2.2p95 (2015-04-13 revision 50295) [x86_64-darwin14]
801+
799802Calculating -------------------------------------
800- String#=~ 69.889k i/100ms
801- String#match 66.715k i/100ms
803+ String#=~ 98.184k i/100ms
804+ Regexp#=== 92.382k i/100ms
805+ String#match 83.601k i/100ms
802806-------------------------------------------------
803- String#=~ 1.854M (±12.2%) i/s - 9.155M
804- String#match 1.594M (±11.0%) i/s - 7.939M
807+ String#=~ 2.442M (± 7.6%) i/s - 12.175M
808+ Regexp#=== 2.259M (± 7.9%) i/s - 11.271M
809+ String#match 1.840M (± 7.3%) i/s - 9.196M
805810
806811Comparison:
807- String#=~: 1853861.7 i/s
808- String#match: 1593971.6 i/s - 1.16x slower
812+ String#=~: 2442335.1 i/s
813+ Regexp#===: 2259277.3 i/s - 1.08x slower
814+ String#match: 1839815.4 i/s - 1.33x slower
809815```
810816
817+ See [ #59 ] ( https://github.com/JuanitoFatas/fast-ruby/pull/59 ) for discussions.
818+
811819
812820##### ` String#gsub ` vs ` String#sub ` [ code] ( code/string/gsub-vs-sub.rb )
813821
0 commit comments