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

Prefer String#tr for other crockford features #215

Merged
merged 4 commits into from
Jul 18, 2022
Merged

Prefer String#tr for other crockford features #215

merged 4 commits into from
Jul 18, 2022

Conversation

kachick
Copy link
Owner

@kachick kachick commented Jul 18, 2022

ref: #213, #102

⚡ This PR makes 2.5x faster parser.

Before

❯ rake benchmark/parsers.rb
/home/kachick/.rubies/ruby-3.1.2/bin/ruby benchmark/parsers.rb
Warming up --------------------------------------
          ULID.parse     9.091k i/100ms
   ULID.from_integer    39.356k i/100ms
Calculating -------------------------------------
          ULID.parse     91.248k (± 5.4%) i/s -    463.641k in   5.097270s
   ULID.from_integer    391.392k (± 2.7%) i/s -      1.968M in   5.031541s

Comparison:
   ULID.from_integer:   391392.3 i/s
          ULID.parse:    91247.8 i/s - 4.29x  (± 0.00) slower

After

❯ rake benchmark/parsers.rb
/home/kachick/.rubies/ruby-3.1.2/bin/ruby benchmark/parsers.rb
Warming up --------------------------------------
          ULID.parse    20.964k i/100ms
    ULID.decode_time    24.609k i/100ms
   ULID.from_integer    34.517k i/100ms
Calculating -------------------------------------
          ULID.parse    210.466k (± 3.7%) i/s -      1.069M in   5.087177s
    ULID.decode_time    258.681k (± 4.7%) i/s -      1.304M in   5.054055s
   ULID.from_integer    335.660k (± 4.1%) i/s -      1.691M in   5.047816s

Comparison:
   ULID.from_integer:   335660.4 i/s
    ULID.decode_time:   258680.8 i/s - 1.30x  (± 0.00) slower
          ULID.parse:   210466.0 i/s - 1.59x  (± 0.00) slower
❯ rake benchmark_with_other_gems
------------------------------------------------------------------------
#### kachick - ruby-ulid(This one)
cd ./benchmark/compare_with_othergems/kachick
bundle install --quiet
bundle exec ruby -v ./parser.rb
ruby 3.1.2p20 (2022-04-12 revision 4491bb740a) [x86_64-linux]
Warming up --------------------------------------
    ULID.decode_time    16.458k i/100ms
Calculating -------------------------------------
    ULID.decode_time    160.777k (±32.3%) i/s -    740.610k in   5.134636s
"`ruby-ulid gem (this one) - 0.6.0.pre` generated products: 1052719 - sample: [2021-04-27 17:27:22.826 UTC, 2021-04-27 17:27:22.826 UTC, 2021-04-27 17:27:22.826 UTC, 2021-04-27 17:27:22.826 UTC, 2021-04-27 17:27:22.826 UTC]"
cd -
------------------------------------------------------------------------
#### rafaelsales - ulid
cd ./benchmark/compare_with_othergems/rafaelsales
bundle install --quiet
bundle exec ruby -v ./parser.rb
ruby 3.1.2p20 (2022-04-12 revision 4491bb740a) [x86_64-linux]
"`ulid gem - 1.3.0` does not have parsers yet"
cd -
------------------------------------------------------------------------
#### abachman - ulid-ruby
cd ./benchmark/compare_with_othergems/abachman
bundle install --quiet
bundle exec ruby -v ./parser.rb
ruby 3.1.2p20 (2022-04-12 revision 4491bb740a) [x86_64-linux]
Warming up --------------------------------------
           ULID.time     5.826k i/100ms
Calculating -------------------------------------
           ULID.time     60.871k (±13.4%) i/s -    302.952k in   5.077365s
"`ulid-ruby gem - 1.0.2` generated products: 417283 - sample: [2021-04-27 17:27:22.826 UTC, 2021-04-27 17:27:22.826 UTC, 2021-04-27 17:27:22.826 UTC, 2021-04-27 17:27:22.826 UTC, 2021-04-27 17:27:22.826 UTC]"
cd -

@kachick kachick added enhancement New feature or request performance Optimized for performance labels Jul 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request performance Optimized for performance
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant