Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Regexp#=== to match and =~ comparison #62

Closed
wants to merge 1 commit into from

Conversation

@JuanitoFatas
Copy link
Owner

commented Aug 7, 2015

@schneems

This comment has been minimized.

Copy link
Contributor

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

This comment has been minimized.

Copy link
Collaborator

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

This comment has been minimized.

Copy link
Contributor

commented Aug 7, 2015

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

@Arcovion

This comment has been minimized.

Copy link
Collaborator

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

This comment has been minimized.

Copy link
Owner Author

commented Nov 4, 2015

Merged in 69c1ed1. Thanks everyone.

@JuanitoFatas JuanitoFatas deleted the string/===-match-=tilde branch Nov 4, 2015

JuanitoFatas added a commit that referenced this pull request Nov 4, 2015

@SamSaffron

This comment has been minimized.

Copy link

commented Dec 25, 2017

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
Projects
None yet
4 participants
You can’t perform that action at this time.