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 1647bc9 commit 502f6f6
Show file tree
Hide file tree
Showing 2 changed files with 27 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
25 changes: 25 additions & 0 deletions tasks/benchmark.rake
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# frozen_string_literal: true

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

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

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

x.compare!
end

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

x.compare!
end
end
end

0 comments on commit 502f6f6

Please sign in to comment.