Last active
June 2, 2018 21:03
-
-
Save Ruin0x11/6af26257b80f15ddcd3dcbbb2b1b9c08 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# usage: ruby compare.rb first.json second.json | |
# gnuplot is required. | |
# produce output.json by running: | |
# make clean | |
# make bench | |
# bin/ElonaFoobar --output json > output.json | |
require "json" | |
class Comparison | |
attr_accessor :charts | |
def initialize() | |
@charts = {} | |
end | |
def add(filename) | |
benchmarks = JSON.parse(File.read(filename))["benchmarks"] | |
datum = {} | |
benchmarks.each do |b| | |
datum[b["name"]] = b | |
end | |
datum.each_pair do |name, data| | |
charts[name] = Chart.new(name) unless charts[name] | |
charts[name].add(filename, data) | |
end | |
end | |
def output | |
@charts.each_value do |c| | |
puts c.output | |
puts | |
File.write("/tmp/plot.csv", c.output) | |
plot = c.plot | |
`echo '#{plot}' | gnuplot > result_#{c.name}.png` | |
end | |
end | |
end | |
class Chart | |
attr_accessor :name, :results | |
def initialize(name) | |
@name = name | |
@results = {} | |
end | |
def add(filename, data) | |
results[filename] = Result.new(filename, data) | |
end | |
def run_count | |
results.first[1].runs.size | |
end | |
def header | |
"Filename,#{run_count.times.collect {|i| "Run#{i}" }.join(",")}" | |
end | |
def output | |
"#{header}\n#{results.map {|n, r| r.output}.join("\n")}" | |
end | |
def plot | |
<<EOF | |
set term png size 800,600 | |
set title "#{@name}" | |
set boxwidth 0.9 absolute | |
set style fill solid 1.00 border lt -1 | |
set key inside right top vertical Right noreverse noenhanced autotitles nobox | |
set style histogram clustered gap 1 title offset character 0, 0, 0 | |
set style data histograms | |
set xtics border in scale 0,0 nomirror rotate by -45 offset character 0, 0, 0 autojustify | |
set xtics norangelimit font ",8" | |
set xtics () | |
set xlabel "Result file" | |
set ylabel "Iteration time (ms)" | |
i = 22 | |
set yrange [0:.01 < * < 100] | |
set style line 1 lc rgb "blue"; | |
set datafile separator "," | |
plot for [i=2:#{run_count+1}] "/tmp/plot.csv" using i:xtic(1) ti col ls 1 | |
EOF | |
end | |
end | |
class Result | |
attr_accessor :filename, :runs | |
def initialize(filename, table) | |
@filename = filename | |
parse table | |
end | |
def parse(table) | |
@name = table["name"] | |
@runs = table["runs"].map do |r| | |
r["duration"] | |
end | |
end | |
def output | |
"#{filename},#{runs.join(",")}" | |
end | |
end | |
comparison = Comparison.new() | |
comparison.add(ARGV[0]) | |
comparison.add(ARGV[1]) | |
comparison.output |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment