#!/bin/sh # SPDX-License-Identifier: GPL-2.0 # # Author: Steve Sistare # # Usage: hackdiff # Print difference between 2 identical series of hackbench runs # # Reads lines from stdin of this form (eg, from runmany): # hackbench 1 process 100000 # 5.753 5.421 5.254 6.044 5.989 Average 5.692 stdev 6.1% # # The first occurrence of a hackbench group line is the base series, and the # next occurrence with identical parameters is the new series. # Convert float $1 to integral fixed-point value with $2 decimal places # ftoi() { declare -i tens=10**$2 echo $(echo "scale=0; ($tens * $1) / 1" | bc -q) } # Convert integral fixed-point $1 with $2 decimal places to floating point # string # itof() { declare -i i frac tens x=$1 tens=10**$2 [[ $x -lt 0 ]] && sign='-' x=(-$x) i=$x/tens frac=$x%tens printf "%s%d.%0${2}d" "$sign" $i $frac } declare -a t1 t2 t3 groups declare -a words declare -a t1 t2 d1 d2 words groups seen_group declare -i i t1d t2d t3 n=0 after=false while read buf ; do if [[ ${buf:0:9} == "hackbench" ]]; then words=($buf) group=${words[1]} if [[ ${seen_group[$group]} == true ]]; then if [[ $after == false ]]; then n=0 after=true fi if [[ ${groups[$n]} != $group ]]; then echo "expected group ${groups[$n]} " \ "but found $group" exit 1 fi fi seen_group[$group]=true groups[$n]=$group elif $(echo $buf | grep -q Average) ; then words=($(echo $buf | sed ' s/^.*Average *//')) if [[ $after == true ]]; then t2[$n]=${words[0]} d=${words[2]} d2[$n]=${d%\%} else t1[$n]=${words[0]} d=${words[2]} d1[$n]=${d%\%} fi n=($n+1) fi done printf "%21s %13s\n" "--- base --" "--- new ---" printf "%6s %6s %6s %6s %6s %8s\n" \ groups time \%stdev time \%stdev \%speedup for ((i=0; i<$n; i++)) ; do t1d=$(ftoi ${t1[$i]} 3) t2d=$(ftoi ${t2[$i]} 3) t3=($t1d*1000/$t2d-1000) t3=($t3*100) speedup=$(itof $t3 3) printf "%6d %6.3f %6.1f %6.3f %6.1f %8.1f\n" \ ${groups[$i]} ${t1[$i]} ${d1[$i]} ${t2[$i]} ${d2[$i]} $speedup done