Skip to content

Commit c2c214f

Browse files
committed
Improve write_csv method to write directly to CSV without intermediate array
1 parent b5db6f0 commit c2c214f

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

lib/benchmark_runner.rb

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,18 +32,17 @@ def write_json(output_path, ruby_descriptions, bench_data)
3232
# Write benchmark results to CSV file
3333
def write_csv(output_path, ruby_descriptions, table)
3434
out_csv_path = "#{output_path}.csv"
35-
output_rows = []
36-
ruby_descriptions.each do |key, value|
37-
output_rows.append([key, value])
38-
end
39-
output_rows.append([])
40-
output_rows.concat(table)
4135

4236
CSV.open(out_csv_path, "wb") do |csv|
43-
output_rows.each do |row|
37+
ruby_descriptions.each do |key, value|
38+
csv << [key, value]
39+
end
40+
csv << []
41+
table.each do |row|
4442
csv << row
4543
end
4644
end
45+
4746
out_csv_path
4847
end
4948

0 commit comments

Comments
 (0)