Zpu-bench - calculating degree of parallelism (DOP)


zpu-bench is the first Zig program that I have written; it was a lot of fun! I have previously implemented a similar program in a combination of Python and C, but this new cleanroom implementation in Zig is self-contained. More polishing is required, but as a first cut this version is stable and useful.

Zig function std.Thread.getCpuCount() reports that my laptop has 4 CPUs. But I also know that it is a dual core processor with hyper-threading enable. If it was a 4 core processor with hyper-threading disabled, Zig would also report the CPU count as 4. However the ability to execute tasks in parallel is vastly different between these two computers. The first computer has a degree of parallism (DOP) of 2 and the latter a DOP of 4.

zpu-bench v0.0.3

CPU = 4
COUNTER_I64 = 43007015647
DOP = 2.003 

real	0m53.167s
user	2m16.139s
sys	0m0.152s

Github repo: GitHub - wfouche/zpu-bench

just in case, simple bash script:



declare -i k=0

echo -e "\tnumb\tphys\tcore\tthrs"
while true; do
        [[ -d $subdir ]] || break
        phy_id=`cat $subdir/physical_package_id`
        cor_id=`cat $subdir/core_id`
        thr_sb=`cat $subdir/thread_siblings_list`
        echo -e "\t$k\t$phy_id\t$cor_id\t$thr_sb"
1 Like