Posts Tagged cpu

Linux CPU benchmark for the Console

Posted by on Thursday, 12 December, 2013

A simple way to compare the CPU speed between two servers:

time echo "scale = 5000; a (1) * 4" | bc -l

This commands calculates Pi to the 5000th decimal place, and returns the time needed to do it.

Sample result:
real 0m16.809s
user 0m15.529s
sys 0m0.024s


How to get CPU information under Linux

Posted by on Tuesday, 7 February, 2012

From time to time I have the need to get basic CPU information out of a server.
There are several tricks available online (like this one and this other one) but I decided to write a small bash script that would spit all this information on a easy to read format.
A friend of mine mentioned that he saw this before somewhere but the writing of the script was a nice exercise.

PHYSICAL=`grep -i "physical id" /proc/cpuinfo | sort -u | wc -l`
LOGICAL=`grep -i "processor" /proc/cpuinfo | sort -u | wc -l`
CORES=`grep -i "cpu cores" /proc/cpuinfo|head -1|awk '{print $4}'`
grep -i "^flags" /proc/cpuinfo|head -1|grep " ht ">/dev/null
if [ $? -eq 0 ] ; then HT="YES" ; else HT="NO"; fi
SIBLINGS=`grep siblings /proc/cpuinfo |head -1 |awk '{print $3}'`
if [ $SIBLINGS -gt $CORES ] ; then HTACTIVE="YES" ; else HTACTIVE="NO" ; fi
echo "Physical CPUs : $PHYSICAL"
echo "Logical CPUs : $LOGICAL"
echo "Cores per CPU : $CORES"
echo "Spport for HT : $HT"
echo "Siblings : $SIBLINGS"
echo "Is HT active : $HTACTIVE"