Skip to content

Instantly share code, notes, and snippets.

@nickabal
Created November 6, 2014 18:24
Show Gist options
  • Save nickabal/c1077db5ab3d3336948a to your computer and use it in GitHub Desktop.
Save nickabal/c1077db5ab3d3336948a to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
# Simple cpu test in bash
# Number of threads
numthreads=64 #Changing this will affect results
#Addition
function count() {
i=0;
while (( i < $1 ));
do (( i ++ ));
done
}
#Multiplication
function multiply() {
i=2;
for j in `seq 0 300000`;
do i=$((i*2));
if [ $i -gt 35184372088832 ];
then i=$((i/23));
fi;
done;
}
#Single Thread Test
start=`date "+%s"`;
count 10000000
end=`date "+%s"`;
singleresult=$((end-start))
#Mutli Thread Combo Test
start=`date "+%s"`;
numtests=2
threads=$((numthreads/numtests))
for j in `seq 1 $threads`; do
count 30000 &
multiply &
done;
wait
end=`date "+%s"`;
multiresult=$((end-start))
p4baselinesingle=167
p4baselinemulti=228
diffs=`echo "scale=2; ( $p4baselinesingle / $singleresult ) * 100" | bc -l`
diffm=`echo "scale=2; ( $p4baselinemulti / $multiresult ) * 100" | bc -l`
echo "Threading"
echo Single: $singleresult
echo "Single: This cpu at $diffs% the speed of a Pentium D 935 @ 3.2Ghz"
echo Multi:: $multiresult
echo "Multi: This cpu at $diffm% the speed of a Pentium D 935 @ 3.2Ghz"
# Results (lower is better):
# Intel Pentium D 935 @ 3.2Ghz }{ S: 167 M: 228
# Intel T7300 @ 2.0Ghz }{ S: 84 M: 129
# AMD Athlon II X3 445 @ 3.1Ghz }{ S: 67 M: 63
# AMD Opteron 2300 8core @ 2.1Ghz }{ S: 101 M: 37
# Intel i5-3570K CPU @ 3.4GHz }{ S: 40 M: 28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment