@@ -786,28 +786,36 @@ Comparison:
786
786
String#=~: 891124.1 i/s - 3.30x slower
787
787
```
788
788
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 )
790
790
791
791
> :warning : <br >
792
792
> Sometimes you can't replace ` match ` with ` =~ ` , <br >
793
793
> 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.
795
797
796
798
```
797
- $ ruby -v code/string/match -vs-=~.rb
799
+ $ ruby -v code/string/=== -vs-=~-vs-match.rb .rb
798
800
ruby 2.2.2p95 (2015-04-13 revision 50295) [x86_64-darwin14]
801
+
799
802
Calculating -------------------------------------
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
802
806
-------------------------------------------------
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
805
810
806
811
Comparison:
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
809
815
```
810
816
817
+ See [ #59 ] ( https://github.com/JuanitoFatas/fast-ruby/pull/59 ) for discussions.
818
+
811
819
812
820
##### ` String#gsub ` vs ` String#sub ` [ code] ( code/string/gsub-vs-sub.rb )
813
821
0 commit comments