Skip to content
This repository was archived by the owner on Jan 22, 2026. It is now read-only.

Commit bc23d39

Browse files
committed
Add benchmarking script for git-pkgs commands
1 parent dbb5621 commit bc23d39

File tree

1 file changed

+92
-0
lines changed

1 file changed

+92
-0
lines changed

bin/benchmark

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
#!/usr/bin/env ruby
2+
# frozen_string_literal: true
3+
4+
require "benchmark"
5+
require "optparse"
6+
7+
options = {
8+
iterations: 3,
9+
repo: nil
10+
}
11+
12+
OptionParser.new do |opts|
13+
opts.banner = "Usage: bin/benchmark [options]"
14+
15+
opts.on("-r", "--repo=PATH", "Path to repository to benchmark against") do |v|
16+
options[:repo] = v
17+
end
18+
19+
opts.on("-n", "--iterations=N", Integer, "Number of iterations per command (default: 3)") do |v|
20+
options[:iterations] = v
21+
end
22+
23+
opts.on("-h", "--help", "Show this help") do
24+
puts opts
25+
exit
26+
end
27+
end.parse!
28+
29+
unless options[:repo]
30+
puts "Error: --repo is required"
31+
puts "Usage: bin/benchmark --repo /path/to/octobox"
32+
exit 1
33+
end
34+
35+
repo_path = File.expand_path(options[:repo])
36+
unless File.directory?(repo_path)
37+
puts "Error: #{repo_path} is not a directory"
38+
exit 1
39+
end
40+
41+
unless File.exist?(File.join(repo_path, ".git", "pkgs.sqlite3"))
42+
puts "Error: #{repo_path} does not have a git-pkgs database"
43+
puts "Run 'git pkgs init' in that repository first"
44+
exit 1
45+
end
46+
47+
iterations = options[:iterations]
48+
gem_root = File.expand_path("..", __dir__)
49+
50+
# Use bundle exec to ensure we run the local development version
51+
commands = {
52+
"blame" => "bundle exec --gemfile=#{gem_root}/Gemfile ruby -I#{gem_root}/lib #{gem_root}/exe/git-pkgs blame --no-pager",
53+
"stale" => "bundle exec --gemfile=#{gem_root}/Gemfile ruby -I#{gem_root}/lib #{gem_root}/exe/git-pkgs stale --no-pager",
54+
"stats" => "bundle exec --gemfile=#{gem_root}/Gemfile ruby -I#{gem_root}/lib #{gem_root}/exe/git-pkgs stats --no-pager",
55+
"log" => "bundle exec --gemfile=#{gem_root}/Gemfile ruby -I#{gem_root}/lib #{gem_root}/exe/git-pkgs log --no-pager",
56+
"list" => "bundle exec --gemfile=#{gem_root}/Gemfile ruby -I#{gem_root}/lib #{gem_root}/exe/git-pkgs list --no-pager"
57+
}
58+
59+
puts "Benchmarking git-pkgs commands"
60+
puts "Repository: #{repo_path}"
61+
puts "Iterations: #{iterations}"
62+
puts "Branch: #{`git rev-parse --abbrev-ref HEAD`.strip}"
63+
puts "Commit: #{`git rev-parse --short HEAD`.strip}"
64+
puts
65+
66+
results = {}
67+
68+
Dir.chdir(repo_path) do
69+
commands.each do |name, cmd|
70+
times = []
71+
72+
# Warmup run
73+
system(cmd, out: File::NULL, err: File::NULL)
74+
75+
iterations.times do |i|
76+
time = Benchmark.realtime do
77+
system(cmd, out: File::NULL, err: File::NULL)
78+
end
79+
times << time
80+
end
81+
82+
avg = times.sum / times.size
83+
min = times.min
84+
max = times.max
85+
results[name] = { avg: avg, min: min, max: max }
86+
87+
puts format("%-10s avg: %6.3fs min: %6.3fs max: %6.3fs", name, avg, min, max)
88+
end
89+
end
90+
91+
puts
92+
puts "Total average: #{format("%.3fs", results.values.sum { |r| r[:avg] })}"

0 commit comments

Comments
 (0)