Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I want to compare servers that run Linux (Centos) against each other - cpu wise.

I thought of taking the sum of all cpus bogomips for comparison, but could only come up with this ugly shell line:

echo 0 `cat /proc/cpuinfo | grep bogomips | cut -d ":" -f 2 | tr " " "+" `| bc

(the 0 is needed because otherwise the line starts with + and is not suitable for bc)

Are there better ways to do this?

share|improve this question
2  
Why would you think that the number of millions of times a CPU can do absolutely nothing per second is any sort of a realistic, or even useful, benchmark? –  Ignacio Vazquez-Abrams Sep 1 '10 at 20:31
    
cat is unnecessary. –  Dennis Williamson Sep 2 '10 at 1:00
    
@Ignacio: What would be a better benchmark? I just need a quick-and-easy way to half a bunch of servers into two halfs, each half should have approximately the same cpu power. –  Philipp Keller Sep 2 '10 at 6:23
add comment

3 Answers 3

up vote 4 down vote accepted
awk -F: '/bogomips/ {sum+=$2} END {print sum}' /proc/cpuinfo
share|improve this answer
    
nice! Didn't know that it is so easy with awk - getting more and more "converted" :-) –  Philipp Keller Sep 2 '10 at 15:21
add comment

Yours is fine (78 byte), it can be shortened by a small amount and linked to a single command (eg. perl)

perl -ne's/mips\s*:\s*(\S+)/$i+=$1/eg; END{print$i}' /proc/cpuinfo

Rounding is straightforward:

perl -ne's/mips\s*:\s*(\S+)/$i+=$1/eg; END{print int($i+0.5)}' /proc/cpuinfo

or, use the autosplit option on ':' (-F)

perl -F: -ane '$i+=$F[1] if $F[0]=~/mips/; END{print $i}' /proc/cpuinfo

Regards

rbo

share|improve this answer
add comment
sed -ne '
/^bogomips/ {
   s/^bogomips[ \t]\+:[ ]\+\([0-9.]\+\)/\1+/
   H
}
$ {
   g
   s/\n//g
   s/+$//
   p
}
d
' /proc/cpuinfo \
   | bc

without decimals:

echo $[`sed -ne '
/^bogomips/ {
   s/^bogomips[ \t]\+:[ ]\+\([0-9]\+\).*/\1+/
   H
}
$ {
   g
   s/\n//g
   s/+$//
   p
}
d
' /proc/cpuinfo`]
share|improve this answer
    
At least in Bash, the $[] form is deprecated. Use $(()) instead. –  Dennis Williamson Sep 2 '10 at 0:58
    
It's probably not necessary to be so meticulous in your regex. The d is unnecessary. sed -ne '/bogomips/ {s/^[^:]*:\(.*\)/\1+/;H}; ${g;s/\n//g;s/+$//;p}' /proc/cpuinfo | bc –  Dennis Williamson Sep 2 '10 at 1:26
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.