Benchmarking the system/CPU performance

2012-01-15 294 words 2 mins read

Have you ever wanted to have a quick check on your CPU performance. I know that lot of people will say that this is not the right way to do this, but here is something that you can use to check the CPU speed.

#!/bin/bash -
#===============================================================================
#
#          FILE:  benchmark.sh
#
#         USAGE:  ./benchmark.sh
#
#   DESCRIPTION:  Benchmark the CPU
#
#       OPTIONS:  ---
#  REQUIREMENTS:  ---
#          BUGS:  ---
#         NOTES:  ---
#        AUTHOR: Amit Agarwal (aka), amit.agarwal@roamware.com
#       COMPANY: Roamware India Pvt Ltd
#       CREATED: 09/21/2011 11:46:03 AM IST
# Last modified: Wed Sep 21, 2011  12:22PM
#      REVISION:  ---
#===============================================================================

add ()
{
    COUNTER=0
    exec 2>&1
    time=$(exec 2>&1;(time while [[  $COUNTER -lt 100000 ]]; do ((COUNTER++)) \
        ; done))
    echo "Time for 100000 additions is "$time
}	# ----------  end of function add  ----------
mul ()
{
    COUNTER=0
    test=2
    exec 2>&1
    time=$(exec 2>&1;(time while [[  $COUNTER -lt 100000 ]]; do ((COUNTER++)) \
        ; ((test=test*2));done))
    echo "Time for 100000 mul is "$time
}	# ----------  end of function add  ----------
div ()
{
    COUNTER=0
    test=1000000000000
    exec 2>&1
    time=$(exec 2>&1;(time while [[  $COUNTER -lt 100000 ]]; do ((COUNTER++)) \
        ; (( test=test/2)); done)|tr -d '\n')
    echo "Time for 100000 divisions is "${time}
}	# ----------  end of function add  ----------

time add
time mul
time div

And here is the output :

Time for 100000 additions is  real 0m1.166s user 0m1.089s sys 0m0.074s

real    0m1.168s
user    0m1.089s
sys    0m0.074s
Time for 100000 mul is  real 0m1.862s user 0m1.778s sys 0m0.082s

real    0m1.863s
user    0m1.779s
sys    0m0.082s
Time for 100000 divisions is  real 0m1.916s user 0m1.825s sys 0m0.089s

real    0m1.918s
user    0m1.825s
sys    0m0.090s

Enhanced by Zemanta

author

Authored By Amit Agarwal

Amit Agarwal, Linux and Photography are my hobbies.Creative Commons Attribution 4.0 International License.

We notice you're using an adblocker. If you like our webite please keep us running by whitelisting this site in your ad blocker. We’re serving quality, related ads only. Thank you!

I've whitelisted your website.

Not now
This website uses cookies to ensure you get the best experience on our website. Learn more Got it