Skip to content

Commit

Permalink
Merge pull request #219 from ifad/chore/extend-benchmark
Browse files Browse the repository at this point in the history
Add other scenarios to benchmark
  • Loading branch information
tagliala authored Sep 17, 2023
2 parents 57f0a70 + aa14920 commit 9fa2934
Showing 1 changed file with 51 additions and 2 deletions.
53 changes: 51 additions & 2 deletions benchmarks/benchmark.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,60 @@

# 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('.as_of.first') do
ITERATIONS.times { Foo.as_of(Time.now).first }
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

x.report('#as_of') do
ITERATIONS.times { first_foo.as_of(Time.now) }
end
end

0 comments on commit 9fa2934

Please sign in to comment.