Skip to content

Instantly share code, notes, and snippets.

@jaspervdj
Created August 16, 2011 09:09
Show Gist options
  • Save jaspervdj/1148707 to your computer and use it in GitHub Desktop.
Save jaspervdj/1148707 to your computer and use it in GitHub Desktop.
Ruby wrapper to run criterion benchmarks one at a time
#!/usr/bin/ruby
require 'tempfile'
if ARGV.length < 1 then
puts "Usage: #{$0} <criterion program> [output CSV file]"
puts "If not supplied, results.csv is used as default CSV filename"
exit 1
end
# Configuration
CRITERION_PROGRAM = ARGV[0]
OUTPUT_FILE = ARGV[1] || "results.csv"
TMP_FILE = 'tmp.csv'
# String in which we collect output
output = ''
# Run every benchmark and append the output
benchmarks = `#{CRITERION_PROGRAM} -l`.lines.collect { |l| l.strip }
benchmarks.each_with_index do |benchmark, i|
puts "(#{i + 1}/#{benchmarks.length}) #{benchmark}..."
`#{CRITERION_PROGRAM} -u "#{TMP_FILE}" "#{benchmark}"`
output += File.read(TMP_FILE)
end
# Write away the results
File.open(OUTPUT_FILE, 'w') do |file|
file.write(output.lines.collect { |l| l.strip }.uniq.join("\n"))
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment