2009-11-14 18:26:44 +01:00
|
|
|
#! /bin/sh
|
|
|
|
|
|
|
|
set -e
|
|
|
|
|
|
|
|
create_src() {
|
|
|
|
n=$1
|
|
|
|
i=0
|
|
|
|
while [ $i -lt $n ]; do
|
|
|
|
file=$i.cc
|
|
|
|
cat <<EOF >$file
|
|
|
|
#include <algorithm>
|
|
|
|
#include <deque>
|
|
|
|
#include <iostream>
|
|
|
|
#include <list>
|
|
|
|
#include <map>
|
|
|
|
#include <set>
|
|
|
|
#include <sstream>
|
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
|
|
|
int var$i;
|
|
|
|
EOF
|
|
|
|
i=$(($i + 1))
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
|
|
|
compile() {
|
|
|
|
n=$1
|
|
|
|
compiler=$2
|
|
|
|
i=0
|
|
|
|
objdir=objs
|
|
|
|
rm -rf $objdir
|
|
|
|
mkdir -p $objdir
|
|
|
|
while [ $i -lt $n ]; do
|
2010-04-28 20:45:03 +02:00
|
|
|
echo -n .
|
2009-11-14 18:26:44 +01:00
|
|
|
$compiler -c $i.cc -O2 -o $objdir/$i.o
|
|
|
|
i=$(($i + 1))
|
|
|
|
done
|
2010-04-28 20:45:03 +02:00
|
|
|
echo
|
2009-11-14 18:26:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
now() {
|
|
|
|
perl -e 'use Time::HiRes qw(time); print time'
|
|
|
|
}
|
|
|
|
|
|
|
|
elapsed() {
|
|
|
|
perl -e 'use Time::HiRes qw(time); printf("%.3f\n", time - $ARGV[0])' $1
|
|
|
|
}
|
|
|
|
|
2010-04-28 08:49:18 +02:00
|
|
|
stat() {
|
|
|
|
desc=$1
|
|
|
|
time=$2
|
|
|
|
ref_time=$3
|
|
|
|
perc=$(perl -e "print 100 * $time / $ref_time")
|
|
|
|
factor=$(perl -e "print $ref_time / $time")
|
2010-04-28 20:45:03 +02:00
|
|
|
printf "%-36s %5.2f s (%6.2f %%) (%5.2f x)\n" "$desc:" $time $perc $factor
|
2010-04-28 08:49:18 +02:00
|
|
|
}
|
|
|
|
|
2009-11-14 18:26:44 +01:00
|
|
|
###############################################################################
|
|
|
|
|
|
|
|
if [ -n "$CXX" ]; then
|
|
|
|
cxx="$CXX"
|
|
|
|
else
|
2010-04-28 08:30:01 +02:00
|
|
|
cxx=/usr/bin/c++
|
2009-11-14 18:26:44 +01:00
|
|
|
fi
|
|
|
|
|
|
|
|
ccache=../ccache
|
|
|
|
tmpdir=tmpdir.$$
|
|
|
|
CCACHE_DIR=.ccache
|
|
|
|
export CCACHE_DIR
|
|
|
|
CCACHE_NODIRECT=1
|
|
|
|
export CCACHE_NODIRECT
|
|
|
|
|
|
|
|
rm -rf $tmpdir
|
|
|
|
mkdir $tmpdir
|
|
|
|
cd $tmpdir
|
|
|
|
|
2010-04-28 08:53:04 +02:00
|
|
|
if [ "$#" -gt 0 ]; then
|
|
|
|
n=$1
|
|
|
|
else
|
|
|
|
n=30
|
|
|
|
fi
|
2009-11-14 18:26:44 +01:00
|
|
|
create_src $n
|
|
|
|
|
|
|
|
echo "Without ccache:"
|
|
|
|
t0=$(now)
|
|
|
|
compile $n $cxx
|
2010-04-28 08:49:18 +02:00
|
|
|
t_wo=$(elapsed $t0)
|
2009-11-14 18:26:44 +01:00
|
|
|
|
|
|
|
echo "With ccache, no direct, cache miss:"
|
|
|
|
t0=$(now)
|
|
|
|
compile $n "$ccache $cxx"
|
2010-04-28 08:49:18 +02:00
|
|
|
t_p_m=$(elapsed $t0)
|
2009-11-14 18:26:44 +01:00
|
|
|
|
|
|
|
echo "With ccache, no direct, cache hit:"
|
|
|
|
t0=$(now)
|
|
|
|
compile $n "$ccache $cxx"
|
2010-04-28 08:49:18 +02:00
|
|
|
t_p_h=$(elapsed $t0)
|
2009-11-14 18:26:44 +01:00
|
|
|
|
|
|
|
unset CCACHE_NODIRECT
|
|
|
|
rm -rf $CCACHE_DIR
|
|
|
|
|
|
|
|
echo "With ccache, direct, cache miss:"
|
|
|
|
t0=$(now)
|
|
|
|
compile $n "$ccache $cxx"
|
2010-04-28 08:49:18 +02:00
|
|
|
t_d_m=$(elapsed $t0)
|
2009-11-14 18:26:44 +01:00
|
|
|
|
|
|
|
echo "With ccache, direct, cache hit:"
|
|
|
|
t0=$(now)
|
|
|
|
compile $n "$ccache $cxx"
|
2010-04-28 08:49:18 +02:00
|
|
|
t_d_h=$(elapsed $t0)
|
|
|
|
|
|
|
|
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
|