Skip to content

Commit

Permalink
add benchmark rake task
Browse files Browse the repository at this point in the history
  • Loading branch information
psimk committed Mar 27, 2024
1 parent b7b71a6 commit 5905fa8
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
2 changes: 2 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ CLEAN.include FileList['**/*{.o,.so,.dylib,.bundle}'],
FileList['**/Makefile'],
FileList['pkg/']

Rake.add_rakelib 'tasks'

desc 'Default: run specs'
task default: [:spec]

Expand Down
45 changes: 45 additions & 0 deletions tasks/benchmark.rake
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# frozen_string_literal: true

require 'benchmark/memory'
require 'benchmark/ips'
require 'prometheus/client'

namespace :benchmark do
task :counter do
counter = Prometheus::Client::Counter.new(:counter, 'Benchmark counter')
counter_exemplar = Prometheus::Client::Counter.new(:counter_exemplar, 'Benchmark exemplar counter')

Benchmark.memory do |x|
x.report('counter.increment') { counter.increment }
x.report('counter_exemplar.increment') { counter_exemplar.increment({}, 1, 'trace_id', '123') }

x.compare!
end

Benchmark.ips do |x|
x.report('counter.increment') { counter.increment }
x.report('counter_exemplar.increment') { counter_exemplar.increment({}, 1, 'trace_id', '123') }

x.compare!
end
end

task :histogram do
histogram = Prometheus::Client::Histogram.new(:histogram, 'Benchmark histogram')
histogram_exemplar = Prometheus::Client::Histogram.new(:histogram_exemplar, 'Benchmark exemplar histogram')

Benchmark.memory do |x|
x.report('histogram.observe') { histogram.observe({}, 1) }
x.report('histogram_exemplar.observe') { histogram_exemplar.observe({}, 1, 'trace_id', '123') }

x.compare!
end

Benchmark.ips do |x|
x.report('histogram.observe') { histogram.observe({}, 1) }
x.report('histogram_exemplar.observe') { histogram_exemplar.observe({}, 1, 'trace_id', '123') }

x.compare!
end
end
end

0 comments on commit 5905fa8

Please sign in to comment.