Skip to content

Benchmark

Kenichi Kamiya edited this page Jul 2, 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`!)
One of the result at 2022/07/02 on my machine
❯ rake benchmark_with_other_gems
------------------------------------------------------------------------
#### 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.919k i/100ms
Calculating -------------------------------------
       ULID.generate     80.622k (±11.1%) i/s -    401.355k in   5.047834s
"`ulid gem - 1.3.0` generated products: 573918 - sample: [\"01G6ZNWY4H3RQKZ932YQ5HN3FS\", \"01G6ZNX0A33CG77AK2V3CXGWDJ\", \"01G6ZNWYZR8EH83EA0JSRSZ5MY\", \"01G6ZNWX37JAP85DWW179854DB\", \"01G6ZNWZEY279CRX1E5VAYTNAV\"]"
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     7.191k i/100ms
Calculating -------------------------------------
       ULID.generate     65.522k (± 9.4%) i/s -    330.786k in   5.094999s
"`ulid-ruby gem - 1.0.2` generated products: 468231 - sample: [\"01G6ZNX5R0S15TWQVBVTSFE0G2\", \"01G6ZNXAKHZF4KPE3DE9ZGRFWT\", \"01G6ZNXAEQXZ2JM3VX8JJDWMHZ\", \"01G6ZNX65RX61EWSHJC5Y6JEJ9\", \"01G6ZNX82WERQP9JTTBFKJP7V7\"]"
cd -
------------------------------------------------------------------------
#### 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.generate.to_s     6.262k i/100ms
Calculating -------------------------------------
  ULID.generate.to_s     55.851k (±11.5%) i/s -    275.528k in   5.002936s
"`ruby-ulid gem (this one) - 0.4.0` generated products: 395963 - sample: [\"01G6ZNXDRP1V807PR4HQMJKEA1\", \"01G6ZNXJZTKR5RY7Y4EP4RZG3K\", \"01G6ZNXH2X6TKXZC7MH9SY2A1B\", \"01G6ZNXEFZ8HPRP4H8RRW8JW3Z\", \"01G6ZNXCQ4EKH02XE76EN484CR\"]"
cd -

I have an excuse, This gem does not aim faster than other. 😋 So I think the results are acceptable.

Clone this wiki locally