Wednesday, February 18, 2015

Bc as CPU benchmark for multicore cpu

Referring to this 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  as follows:

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 ./ ::: 2000 2000 2000 2000

We can determine the number of cores with this command:

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

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

Convert string into hex - iwconfig wifi key

I've played a bit with my wifi command line configuration. The iwconfig command needs the key represented as hexadecimal string, so here is the formula to convert string into hex. The od command does the work and tr command removes spaces:

$ echo -n "mykey" | od -A n -t x1 | tr -d ' '

Note: we need to escape special shell symbols

$ echo -n "mykey\$\$" | od -A n -t x1 | tr -d ' '

As I found out later the string can be given as parameter to the iwconfig key :).