Skip to content

Conversation

@schneems
Copy link
Contributor

schneems commented Aug 7, 2015

Confirm

Calculating ------------------------------------- String#=~ 67.365k i/100ms Regexp#=== 63.076k i/100ms String#match 56.745k i/100ms ------------------------------------------------- String#=~ 1.645M (±12.9%) i/s - 8.084M Regexp#=== 1.511M (±12.1%) i/s - 7.443M String#match 1.208M (±15.2%) i/s - 5.901M 

Weird, I could have sworn I saw it faster earlier

@Arcovion
Copy link
Collaborator

Arcovion commented Aug 7, 2015

Hmm, yea very little in it. They do different things too, with Regexp#=== returning a boolean (which is handy, as before I knew that I used !!str[/match/]).
I think it's good to include, to show that they are equally fast.

@schneems
Copy link
Contributor

schneems commented Aug 7, 2015

String#=~ is (1.645 - 1.511 ) / 1.511 #=> 8 % faster

@Arcovion
Copy link
Collaborator

Arcovion commented Aug 7, 2015

Same benchmark:

Calculating ------------------------------------- String#=~ 138.285k i/100ms Regexp#=== 130.622k i/100ms String#match 112.077k i/100ms ------------------------------------------------- String#=~ 3.273M (± 2.6%) i/s - 16.456M Regexp#=== 3.406M (± 4.3%) i/s - 16.981M String#match 2.714M (± 2.8%) i/s - 13.561M Comparison: Regexp#===: 3406168.4 i/s String#=~: 3273161.4 i/s - 1.04x slower String#match: 2714176.6 i/s - 1.25x slower 
ruby 2.2.2p95 (2015-04-13 revision 50295) [x64-mingw32] 

Mine has the lowest standard deviation @ ± 4.3%, also higher IPS
Essentially equal for me.

Edit: Ran it again, got similar to #59 (comment) but higher IPS:

Calculating ------------------------------------- String#=~ 143.101k i/100ms Regexp#=== 138.872k i/100ms String#match 118.070k i/100ms ------------------------------------------------- String#=~ 3.332M (± 1.9%) i/s - 16.743M Regexp#=== 3.482M (± 1.5%) i/s - 17.498M String#match 2.746M (± 1.2%) i/s - 13.814M Comparison: Regexp#===: 3481922.4 i/s String#=~: 3332209.4 i/s - 1.04x slower String#match: 2745894.1 i/s - 1.27x slower 
@JuanitoFatas
Copy link
Contributor Author

Merged in 69c1ed1. Thanks everyone.

@JuanitoFatas JuanitoFatas deleted the string/===-match-=tilde branch November 4, 2015 09:36
JuanitoFatas added a commit that referenced this pull request Nov 4, 2015
@SamSaffron
Copy link

Got to add "test".match?(/e/) as well cause that is fastest.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
4 participants