Skip to content

Commit

Permalink
Add other scenarios to benchmark
Browse files Browse the repository at this point in the history
Comparison:

Master @ c25a157

```
                                 user     system      total        real
.merge                       0.049643   0.000139   0.049782 (  0.049780)
.first                       0.620854   0.020477   0.641331 (  0.719452)
.last                        0.657637   0.019880   0.677517 (  0.755410)
History.merge                0.056640   0.000203   0.056843 (  0.056840)
History.first                0.746947   0.021832   0.768779 (  0.969067)
History.last                 0.801237   0.021547   0.822784 (  1.022579)
#history.first               0.997884   0.023723   1.021607 (  1.374740)
#history.last                1.078028   0.024214   1.102242 (  1.455553)
```

Master after #217 and #218:

```
                                 user     system      total        real
.merge                       0.049869   0.000134   0.050003 (  0.050000)
.first                       0.562156   0.018678   0.580834 (  0.656834)
.last                        0.604508   0.019646   0.624154 (  0.701138)
History.merge                0.056813   0.000197   0.057010 (  0.057004)
History.first                0.688581   0.021208   0.709789 (  0.908478)
History.last                 0.744874   0.021590   0.766464 (  0.965443)
#history.first               0.938423   0.022830   0.961253 (  1.313174)
#history.last                1.018122   0.023720   1.041842 (  1.393156)
```

[ci skip]
  • Loading branch information
tagliala committed Sep 17, 2023
1 parent 57f0a70 commit bdf91a7
Showing 1 changed file with 43 additions and 2 deletions.
45 changes: 43 additions & 2 deletions benchmarks/benchmark.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,52 @@

# frozen_string_literal: true

unless ENV['COVERAGE'].nil?
require 'simplecov'

SimpleCov.start
SimpleCov.command_name 'Bench'
end

require_relative 'benchmark_sample'
require 'benchmark'

ITERATIONS = 5_000

Foo.create! name: 'Ciao'

first_foo = Foo.first

Benchmark.bmbm(30) do |x|
x.report('benchmark_sample') do
run_benchmark_sample
x.report('.merge') do
ITERATIONS.times { Foo.all.merge(Foo.all) }
end

x.report('.first') do
ITERATIONS.times { Foo.first }
end

x.report('.last') do
ITERATIONS.times { Foo.last }
end

x.report('History.merge') do
ITERATIONS.times { Foo::History.all.merge(Foo::History.all) }
end

x.report('History.first') do
ITERATIONS.times { Foo::History.first }
end

x.report('History.last') do
ITERATIONS.times { Foo::History.last }
end

x.report('#history.first') do
ITERATIONS.times { first_foo.history.first }
end

x.report('#history.last') do
ITERATIONS.times { first_foo.history.last }
end
end

0 comments on commit bdf91a7

Please sign in to comment.