Skip to content

Commit 4b2eacf

Browse files
Allow optional deletion of the raw json results.
This allows downstream users of ruby-bench to configure where the results.json files are to be stored, so they can use them directly, rather than having them deleted by ruby-bench after processing
1 parent e43471e commit 4b2eacf

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

lib/benchmark_suite.rb

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,16 @@ def run(ruby:, ruby_description:)
4343
benchmark_entries = discover_benchmarks
4444
cmd_prefix = base_cmd(ruby_description)
4545
env = benchmark_env(ruby)
46+
caller_json_path = ENV["RESULT_JSON_PATH"]
4647

4748
benchmark_entries.each_with_index do |entry, idx|
4849
puts("Running benchmark \"#{entry.name}\" (#{idx+1}/#{benchmark_entries.length})")
4950

50-
result_json_path = File.join(out_path, "temp#{Process.pid}.json")
51+
result_json_path = caller_json_path || File.join(out_path, "temp#{Process.pid}.json")
5152
result = run_single_benchmark(entry.script_path, result_json_path, ruby, cmd_prefix, env)
5253

5354
if result[:success]
54-
bench_data[entry.name] = process_benchmark_result(result_json_path, result[:command])
55+
bench_data[entry.name] = process_benchmark_result(result_json_path, result[:command], delete_file: !caller_json_path)
5556
else
5657
bench_failures[entry.name] = result[:status].exitstatus
5758
end
@@ -74,10 +75,10 @@ def setup_benchmark_directories
7475
end
7576
end
7677

77-
def process_benchmark_result(result_json_path, command)
78+
def process_benchmark_result(result_json_path, command, delete_file: true)
7879
JSON.parse(File.read(result_json_path)).tap do |json|
7980
json["command_line"] = command
80-
File.unlink(result_json_path)
81+
File.unlink(result_json_path) if delete_file
8182
end
8283
end
8384

0 commit comments

Comments
 (0)