Wednesday, February 18, 2015

Bc as CPU benchmark for multicore cpu

Referring to this http://tuxshell.blogspot.com/2009/08/bc-as-cpu-benchmark.html post, I figured out the simple way how to test speed of multicore cpu system or multi cpu system. This command:

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

will only be executed on one CPU core. However we can use GNU parallel command to execute it many times on multicore cpu. First we create benchmark script b.sh  as follows:

#!/bin/bash
echo "scale=$1; a(1)*4" | bc -l


The first argument is number of digits to calculate. Now we can run in parallel (4 times) this way

$ time parallel ./b.sh ::: 2000 2000 2000 2000

We can determine the number of cores with this command:

$ cat /proc/cpuinfo  | grep processor | wc -l
4

If your cpu supports hyper threading - this will give you the number of logical cores, not only the physical ones




6 comments:

  1. Raspberry Pi 3 - Raspbian-lite 4.1.19-v7+
    4 core ARM Cortext-A53 1.2GHz 1GB (128MB for display)

    Single core 2000 result:
    real 0m8.045s
    user 0m8.030s
    sys 0m0.010s

    4 core 2000 result:
    real 0m8.761s
    user 0m32.120s
    sys 0m0.080s

    ReplyDelete
  2. I don't think this affects timing as what it essentially does is calculate Pi using 4 cores, 4 times in parallel, it doesn't actually increase the speed of these calculations.
    to test threads, this would have to be a list or something similar.
    This does however do a good job at testing how well multicore cpus work and could be used to measure power consumption.

    ReplyDelete
  3. ...or you could just skip the script file and pass everything to parallel right away as an one-liner
    parallel echo "scale={}\; a\(1\)\*4" '|' bc -l ::: 2000 2000 2000 2000

    ReplyDelete
  4. alternatively you could have this (a for loop in disguise)
    seq 4|parallel -N 0 echo "scale=2000\; a\(1\)\*4" '|' bc -l

    GNU parallel seems really versatile

    ReplyDelete
  5. or this, without any cryptic parts, that you can always remember
    time seq 4|parallel -N 0 echo "2^2^22" '|' bc
    As long as it has bc crunching numbers, it's job done!
    Cheers!

    ReplyDelete