Skip to content

Commit

Permalink
Add gnuplot summary script
Browse files Browse the repository at this point in the history
This script should allow easier comparisons between terminal emulators,
without requiring all benchmark results to be mashed together into a
single unclear plot.
  • Loading branch information
chrisduerr committed Sep 19, 2020
1 parent de2bca1 commit 6a781df
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 3 deletions.
12 changes: 9 additions & 3 deletions gnuplot.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#!/usr/bin/env sh

# Plot every sample of all benchmarks.

# Make sure gnuplot is installed.
if ! [ -x "$(command -v gnuplot)" ]; then
echo "command not found: gnuplot"
Expand All @@ -18,8 +20,8 @@ output_file=${!output_index}

# Setup gnuplot script with output format and file.
gnuplot_script="\
set terminal svg noenhanced\n\
set output \"${output_file}\"\n\
set terminal svg noenhanced size 1000,750
set output \"${output_file}\"
set xlabel \"samples\"
set ylabel \"milliseconds (lower is better)\"
plot "
Expand All @@ -28,7 +30,11 @@ plot "
for input_index in $(seq 1 $(($# - 1))); do
input_file=${!input_index}
num_cols=$(cat "$input_file" | head -n 1 | awk '{ print NF }')
gnuplot_script+="for[col = 1:${num_cols}] \"$input_file\" using col with linespoint title \"$input_file: \".columnhead(col),"
gnuplot_script+="for[col = 1:${num_cols}] \
\"$input_file\" \
using col \
with linespoint \
title \"$input_file: \".columnhead(col),"
done
gnuplot_script=${gnuplot_script::-1}

Expand Down
73 changes: 73 additions & 0 deletions gnuplot_summary.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
#!/usr/bin/env sh

# Plot a summary for each benchmark.

box_width=2
gap_size=2

# Make sure gnuplot is installed.
if ! [ -x "$(command -v gnuplot)" ]; then
echo "command not found: gnuplot"
exit 1
fi

# Ensure at least one input and output file is present.
if [ $# -lt 2 ]; then
echo "Usage: gnuplot.sh <INPUT_FILES>... <OUTPUT_FILE>"
exit 1
fi

# Use last argument as output file.
output_index=$#
output_file=${!output_index}

# Setup gnuplot script with output format and file.
gnuplot_script="\
set terminal svg noenhanced size 1000,750
set output \"${output_file}\"
set ylabel \"milliseconds (lower is better)\"
set style fill solid 0.25 border -2
set style boxplot nooutliers
set style data boxplot
set key above
set boxwidth 1.8\n"

num_inputs=$(($# - 1))
bench_width=$((box_width * num_inputs + gap_size))

# Use column headers as x tic labels.
gnuplot_tics="set xtics scale 0 ("
index=1
for column_label in $(cat "$1" | head -n 1); do
value=$((index * bench_width + num_inputs / 2))
gnuplot_tics+="\"$column_label\" $value,"

# Draw separator grid between benchmarks.
if [ $index -ne 1 ]; then
separator_value=$((index * bench_width - box_width / 2 - gap_size / 2))
gnuplot_script+="set arrow $index \
from $separator_value, graph 0 \
to $separator_value, graph 1 \
nohead dt \".\" linecolor \"#888888\"\n"
fi

index=$((index + 1))
done
gnuplot_tics="${gnuplot_tics::-1}) rotate by 315 left\n"
gnuplot_script+=$gnuplot_tics

# Get the mean for all columns in every file.
gnuplot_script+="plot "
for input_index in $(seq 1 $num_inputs); do
input_file=${!input_index}
num_cols=$(cat "$input_file" | head -n 1 | awk '{ print NF }')
gnuplot_script+="for[col = 1:${num_cols}] \
\"$input_file\" \
using (col * $bench_width + $((box_width * (input_index - 1)))):col \
title (col == 1 ? \"$input_file\" : \"\") \
linecolor $input_index,"
done
gnuplot_script=${gnuplot_script::-1}

# Plot everything.
echo -e "$gnuplot_script" | gnuplot

0 comments on commit 6a781df

Please sign in to comment.