perl -e 'use Time::HiRes qw(time); printf("%.3f\n", time - $ARGV[0])' $1
}
+stat() {
+ desc=$1
+ time=$2
+ ref_time=$3
+ perc=$(perl -e "print 100 * $time / $ref_time")
+ factor=$(perl -e "print $ref_time / $time")
+ printf "%-36s %.3f s (%6.2f %%) (%5.2f x)\n" "$desc:" $time $perc $factor
+}
+
###############################################################################
if [ -n "$CXX" ]; then
echo "Without ccache:"
t0=$(now)
compile $n $cxx
-echo "Time: $(elapsed $t0)"
+t_wo=$(elapsed $t0)
+echo "Time: $t_wo"
echo "With ccache, no direct, cache miss:"
t0=$(now)
compile $n "$ccache $cxx"
-echo "Time: $(elapsed $t0)"
+t_p_m=$(elapsed $t0)
+echo "Time: $t_p_m"
echo "With ccache, no direct, cache hit:"
t0=$(now)
compile $n "$ccache $cxx"
-echo "Time: $(elapsed $t0)"
+t_p_h=$(elapsed $t0)
+echo "Time: $t_p_h"
unset CCACHE_NODIRECT
rm -rf $CCACHE_DIR
echo "With ccache, direct, cache miss:"
t0=$(now)
compile $n "$ccache $cxx"
-echo "Time: $(elapsed $t0)"
+t_d_m=$(elapsed $t0)
+echo "Time: $t_d_m"
echo "With ccache, direct, cache hit:"
t0=$(now)
compile $n "$ccache $cxx"
-echo "Time: $(elapsed $t0)"
+t_d_h=$(elapsed $t0)
+echo "Time: $t_d_h"
+
+echo
+stat "Without ccache" $t_wo $t_wo
+stat "With ccache, no direct, cache miss" $t_p_m $t_wo
+stat "With ccache, no direct, cache hit" $t_p_h $t_wo
+stat "With ccache, direct, cache miss" $t_d_m $t_wo
+stat "With ccache, direct, cache hit" $t_d_h $t_wo