Skip to content

Commit 0d2fb18

Browse files
committed
benchmark: output CSV, SVG and PDF
1 parent aabb8f6 commit 0d2fb18

File tree

3 files changed

+86
-11
lines changed

3 files changed

+86
-11
lines changed

.github/workflows/test.yaml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,21 @@ jobs:
7777
PGHOST: /var/run/postgresql
7878
run: |
7979
bundle exec rake
80+
- name: Install benchmark dependencies
81+
run: |
82+
sudo apt install -y -V \
83+
gr-framework-plugin-base \
84+
gr-framework-plugin-full \
85+
libgr-framework-dev
8086
- name: Benchmark
8187
env:
8288
PGHOST: /var/run/postgresql
8389
run: |
8490
bundle exec benchmark/load-dump.rb
91+
- uses: actions/upload-artifact@v4
92+
with:
93+
name: benchmark
94+
path: |
95+
*.csv
96+
*.svg
97+
*.pdf

Gemfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ end
1717
group :benchmark do
1818
gem "benchmark"
1919
gem "pg"
20+
gem "ruby-gr"
2021
end
2122

2223
group :test do

benchmark/load-dump.rb

Lines changed: 72 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#!/usr/bin/env ruby
22

33
require "benchmark"
4+
require "grm"
45
require "pg"
56
require_relative "../lib/activerecord-adbc-adapter"
67

@@ -101,28 +102,88 @@ class AdbcLog < ActiveRecord::Base
101102
end
102103
arrow_table = Arrow::Table.new(arrow_columns)
103104

104-
Benchmark.bm do |benchmark|
105-
benchmark.report("SQL: Load") do
105+
puts("Load:")
106+
load_results = Benchmark.bm do |benchmark|
107+
benchmark.report("SQL") do
106108
SqlLog.connection.execute(sql_load)
107109
end
108110

109-
benchmark.report("SQL: Dump") do
110-
SqlLog.connection.execute(sql_dump)
111+
benchmark.report("Active Record") do
112+
ActiveRecordLog.insert_all(raw_records)
111113
end
112114

113-
benchmark.report("Active Record: Load") do
114-
ActiveRecordLog.insert_all(raw_records)
115+
benchmark.report("ADBC") do
116+
AdbcLog.ingest(arrow_table)
115117
end
118+
end
116119

117-
benchmark.report("Active Record: Dump") do
118-
ActiveRecordLog.pluck
120+
File.open("load.csv", "w") do |csv|
121+
csv.puts("approach,elapsed_time")
122+
load_results.each do |result|
123+
csv.puts("#{result.label},#{result.real}")
119124
end
125+
end
120126

121-
benchmark.report("ADBC: Load") do
122-
AdbcLog.ingest(arrow_table)
127+
puts
128+
puts("Dump:")
129+
dump_results = Benchmark.bm do |benchmark|
130+
benchmark.report("SQL") do
131+
SqlLog.connection.execute(sql_dump)
132+
end
133+
134+
benchmark.report("Active Record") do
135+
ActiveRecordLog.pluck
123136
end
124137

125-
benchmark.report("ADBC: Dump") do
138+
benchmark.report("ADBC") do
126139
AdbcLog.all.to_arrow
127140
end
128141
end
142+
143+
File.open("dump.csv", "w") do |csv|
144+
csv.puts("approach,elapsed_time")
145+
dump_results.each do |result|
146+
csv.puts("#{result.label},#{result.real}")
147+
end
148+
end
149+
150+
151+
results = [
152+
{title: "Load", results: load_results},
153+
{title: "Dump", results: dump_results},
154+
]
155+
n_results = results.size
156+
x_margin = 0.0
157+
x_width = (1 / n_results.to_f) - (x_margin * 2)
158+
y_min = 0.05
159+
y_max = 0.95
160+
all_reals = results.collect do |results|
161+
results[:results].collect do |result|
162+
result[:real]
163+
end
164+
end
165+
y_range = [0.0, all_reals.flatten.max]
166+
subplots = results.each_with_index.collect do |data, i|
167+
x_index = (i - 1) % n_results
168+
x_margin_right = x_margin + (2 * x_margin * i)
169+
position = [
170+
x_width * i + x_margin_right,
171+
x_width * (i + 1) + x_margin_right,
172+
y_min,
173+
y_max,
174+
]
175+
{
176+
kind: "barplot",
177+
title: data[:title],
178+
c: n_results.times.collect {|j| j + 2},
179+
x_label: "Approach",
180+
y: data[:results].collect {|result| result[:real]},
181+
y_label: "Elapsed time (s)",
182+
y_labels: data[:results].collect {|result| result[:label]},
183+
y_range: y_range,
184+
subplot: position,
185+
}
186+
end
187+
GRM.merge(subplots: subplots, size: [1200, 600])
188+
GRM.export("load-dump.png")
189+
GRM.export("load-dump.svg")

0 commit comments

Comments
 (0)