Skip to content

Benchmark

Kenichi Kamiya edited this page Aug 5, 2022 · 12 revisions

How to run benchmarks for this gem's features

There is some benchmarks

$ rake --tasks | grep 'benchmark'
rake benchmark/core_instance_methods.rb   # Rough benchmark for core_instance_methods.rb
rake benchmark/extra_instance_methods.rb  # Rough benchmark for extra_instance_methods.rb
rake benchmark/generators.rb              # Rough benchmark for generators.rb
rake benchmark/sample.rb                  # Rough benchmark for sample.rb
rake benchmark/sort.rb                    # Rough benchmark for sort.rb
rake benchmark_with_other_gems            # Compare generating String performance with other gems

How to compare with other gem's performance

This runs rough benchmarks

$ rake benchmark_with_other_gems
(Do not use `bundle exec`!)

See #213, 215 and 217 for further detail

Below is a snapshot results on 2022-08-05 with 0.7.0

❯ rake benchmark_with_other_gems
------------------------------------------------------------------------
#### kachick - ruby-ulid(This one)
cd ./benchmark/compare_with_othergems/kachick
bundle install --quiet
bundle exec ruby -v ./generate.rb
ruby 3.1.2p20 (2022-04-12 revision 4491bb740a) [x86_64-linux]
Warming up --------------------------------------
         ULID.encode    12.682k i/100ms
Calculating -------------------------------------
         ULID.encode    121.187k (±14.3%) i/s -    596.054k in   5.042449s
"`ruby-ulid gem (this one) - 0.7.0` generated products: 839137 - sample: [\"01G9Q01S1RMP1ZEPZF9TMVMSX5\", \"01G9Q01K649XQC9M4CAGAENSQ7\", \"01G9Q01PVW5T293MV5D9T9TKP7\", \"01G9Q01JDKSHCHQR3KRGVX0T8D\", \"01G9Q01QJYXNJTX9NCP3665MV6\"]"
bundle exec ruby -v ./parser.rb
ruby 3.1.2p20 (2022-04-12 revision 4491bb740a) [x86_64-linux]
Warming up --------------------------------------
    ULID.decode_time    14.275k i/100ms
Calculating -------------------------------------
    ULID.decode_time    144.323k (±27.9%) i/s -    670.925k in   5.005166s
"`ruby-ulid gem (this one) - 0.7.0` generated products: 959021 - 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 ./generate.rb
ruby 3.1.2p20 (2022-04-12 revision 4491bb740a) [x86_64-linux]
Warming up --------------------------------------
       ULID.generate     8.363k i/100ms
Calculating -------------------------------------
       ULID.generate     74.763k (±10.7%) i/s -    376.335k in   5.095863s
"`ulid gem - 1.3.0` generated products: 533863 - sample: [\"01G9Q023JQXA5XXEFHP10P0DDN\", \"01G9Q023AF5XFRJJ62H0R6K9AN\", \"01G9Q0297ASWNKVKXY377MSRV4\", \"01G9Q029HEQ8DRF5DK70638JVQ\", \"01G9Q027TX31PVM3WD9NZX777M\"]"
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 ./generate.rb
ruby 3.1.2p20 (2022-04-12 revision 4491bb740a) [x86_64-linux]
Warming up --------------------------------------
       ULID.generate     6.795k i/100ms
Calculating -------------------------------------
       ULID.generate     61.254k (± 9.1%) i/s -    305.775k in   5.037210s
"`ulid-ruby gem - 1.0.2` generated products: 432465 - sample: [\"01G9Q02DZ12FXF8W8VY2TG4AS6\", \"01G9Q02GV57J3KAC15XSWK63PT\", \"01G9Q02FMK85AD6165RZ3WJ0JR\", \"01G9Q02GX6FA28PG3GZK2T9NQN\", \"01G9Q02FNF8JQAJZQGVDMRKVV6\"]"
bundle exec ruby -v ./parser.rb
ruby 3.1.2p20 (2022-04-12 revision 4491bb740a) [x86_64-linux]
Warming up --------------------------------------
           ULID.time     5.773k i/100ms
Calculating -------------------------------------
           ULID.time     55.385k (±10.5%) i/s -    277.104k in   5.056638s
"`ulid-ruby gem - 1.0.2` generated products: 390693 - 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 -
irb(main):002:0> Rational(121.187, 74.763).to_f
=> 1.6209488650803203
irb(main):003:0> Rational(121.187, 61.254).to_f
=> 1.9784340614490483
irb(main):004:0> Rational(144.323, 55.385).to_f
=> 2.605813848514941

This project does not prioritize the speed. However it actually works faster than others! ⚡⚡

Clone this wiki locally