CPU benchmarking utility for Linux
Solution 1:
Actually there is a a tool named sysbench
.
You can install it with:
sudo apt-get install sysbench
To CPU benchmarking you can do like
sysbench --test=cpu --cpu-max-prime=20000 run
where 20000 is like max event count.
Solution 2:
Alternatively, one can use stress-ng
. It has a CPU stress test as one of the many stress tests built into the tool. The cpu stress test contains many different CPU stress methods covering integer, floating point, bit operations, mixed compute, prime computation, and a wide range of computations.
Install using:
sudo apt-get install stress-ng
To see the cpu related stress methods use:
stress-ng --cpu-method which
To benchmark, for example, matrix product for 60 seconds on 4 CPU threads, use:
stress-ng --cpu 4 --cpu-method matrixprod --metrics-brief --perf -t 60
stress-ng: info: [15876] dispatching hogs: 4 cpu
stress-ng: info: [15876] successful run completed in 60.00s (1 min, 0.00 secs)
stress-ng: info: [15876] stressor bogo ops real time usr time sys time bogo ops/s bogo ops/s
stress-ng: info: [15876] (secs) (secs) (secs) (real time) (usr+sys time)
stress-ng: info: [15876] cpu 71657 60.00 239.60 0.00 1194.25 299.07
stress-ng: info: [15876] cpu:
stress-ng: info: [15876] 885,244,279,148 CPU Cycles 14.75 B/sec
stress-ng: info: [15876] 1,289,303,858,968 Instructions 21.49 B/sec (1.456 instr. per cycle)
stress-ng: info: [15876] 201,499,961,692 Cache References 3.36 B/sec
stress-ng: info: [15876] 790,424 Cache Misses 13.17 K/sec ( 0.00%)
stress-ng: info: [15876] 157,689,508,544 Branch Instructions 2.63 B/sec
stress-ng: info: [15876] 1,232,539,732 Branch Misses 20.54 M/sec ( 0.78%)
stress-ng: info: [15876] 5,755,605,036 Bus Cycles 95.92 M/sec
stress-ng: info: [15876] 817,296,440,876 Total Cycles 13.62 B/sec
stress-ng: info: [15876] 8,532 Page Faults Minor 142.19 sec
stress-ng: info: [15876] 0 Page Faults Major 0.00 sec
stress-ng: info: [15876] 220 Context Switches 3.67 sec
stress-ng: info: [15876] 0 CPU Migrations 0.00 sec
stress-ng: info: [15876] 0 Alignment Faults 0.00 sec
Solution 3:
Old question (with no selected answer yet 😱)
But I recently was looking for a tool available in multiple "distros" (Termux not really being a distro) including Ubuntu, and while the above mentioned packages are a common good choice, I read here: https://linuxhint.com/useful_linux_stress_test_benchmark_cpu_perf/ that 7-zip has a built-in benchmarking tool! And 7zip can be found in nearly every distros repository.
To run a single-thread benchmark:
7z b -mmt1
To run a multi-thread benchmark:
7z b
Results from my Pixel 2 phone:
7-Zip [64] 16.02 : Copyright (c) 1999-2016 Igor Pavlov : 2016-05-21
p7zip Version 16.02 (locale=utf8,Utf16=on,HugeFiles=on,64 bits,8 CPUs LE)
LE
CPU Freq: 1509 2234 2434 2447 2433 2406 2430 2425 2400
RAM size: 3657 MB, # CPU hardware threads: 8
RAM usage: 435 MB, # Benchmark threads: 1
Compressing | Decompressing
Dict Speed Usage R/U Rating | Speed Usage R/U Rating
KiB/s % MIPS MIPS | KiB/s % MIPS MIPS
22: 1666 99 1631 1621 | 30427 100 2608 2598
23: 1602 99 1644 1633 | 29815 100 2589 2581
24: 1517 99 1644 1632 | 29441 100 2595 2585
25: 1397 99 1607 1596 | 28748 100 2567 2559
---------------------------------- | ------------------------------
Avr: 99 1632 1620 | 100 2590 2581
Tot: 99 2111 2100
Solution 4:
phoronix-test-suite
sudo apt-get install phoronix-test-suite
phoronix-test-suite list-available-suites
# Chose one, and run it.
phoronix-test-suite run pts/cpu
Benchmarks several real world CPU-heavy use cases like compression, encryption and databases.
Beware that pts/cpu
and other benchmarks takes up a few gigabytes of disk space. This might imply that they have more realistic workloads.
Tested on Ubuntu 16.10.