112

I am looking for a utility that will benchmark CPU performance under single and multi threaded instances. At present I have an old rig with a dual core CPU (E7500) at 3.6 Ghz and I am looking at replacing it with a quad core CPU (Q9400) at 3.2 Ghz. I want to see if I will notice a performance improvement with the extra 2 cores (albeit with a drop in core speed). I will clock the CPU's with the same FSB (400Mhz) and the cache size is the same per CPU (1.5MB) and for what its worth I have 4GB ram (with potential to upgrade to 6GB)

My son mainly uses the PC for playing TF2 (which I am trying to still get working under Linux) and I also use it for some video encoding (MP4 to DVD)

I am thinking that I could be better off with the quad core but any feedback would be appreciated.

1
  • 5
    There is Geekbench which can compare CPUs (there are already existing test results for the e7500 and the q9400, though many are in drastically different setups, which will have different bus speeds etc.
    – Wilf
    Jun 10, 2015 at 10:18

5 Answers 5

136

Actually there is a a tool named sysbench.

You can install it with:

sudo apt-get install sysbench

To do CPU benchmarking you can use:

sysbench cpu run

This will run a single-threaded CPU benchmark. To use more than one thread, use:

sysbench --threads=16 cpu run
9
  • 11
    --cpu-max-prime=20000 is optional, the default being 10000. I suggest to keep the default and fiddle with --max-requests instead (which is the number of operations performed)
    – MestreLion
    Mar 22, 2016 at 17:29
  • 23
    Also note that by default this is a single-threaded test. For testing N cores you can use --num-threads=N, and compare results using the per-request statistics output.
    – MestreLion
    Mar 22, 2016 at 17:31
  • 3
    Is there a place to compare the output to get relative performance?
    – jjxtra
    Sep 13, 2019 at 22:33
  • 3
    With newer version, the --test= option can be omitted, just use sysbench cpu.... Otherwise sysbench 1.0.18 prints: WARNING: the --test option is deprecated. You can pass a script name or path on the command line without any options.
    – ckujau
    Feb 16, 2020 at 22:30
  • 3
    @MestreLion WARNING: --num-threads is deprecated, use --threads instead
    – Madacol
    Sep 3, 2020 at 21:33
42

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  
11
  • 3
    " Unable to locate package stress-ng!" Feb 5, 2016 at 0:09
  • 1
    If you have an older release, stress-ng won't be available from the archive. However, they are packaged in ppa:colin-king/white Mar 3, 2016 at 16:56
  • 2
    From the stress-ng manpage: "stress-ng can also measure test throughput rates; this can be useful to observe performance changes across different operating system releases or types of hardware. However, it has never been intended to be used as a precise benchmark test suite, so do NOT use it in this manner."
    – Michael F
    Feb 23, 2018 at 10:17
  • 6
    As the author of stress-ng, I'd better elaborate on this. stress-ng is good enough to get some comparative benchmarks results out of it, but it is not been thoroughly calibrated to say how much deviation there is on the each specific stressor. I therefore suggest running a stress-ng stressor several times and seeing how much variation there is on a specific stress test, and if it does not vary much, then it can be considered reliable enough for a benchmark for that specific use case. It all depends on now noisy/busy a system is, how well I/O performs, if it swaps, etc. Feb 23, 2018 at 11:49
  • 4
    Comparing stress-ng and sysbench, one tells me that system A is faster (125%), the other tells me that system B is faster (140%), which one is correct?
    – W.M.
    Aug 8, 2019 at 14:40
35

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
5
  • 3
    It works nice with option -mm=* to run several tests. E.g. 7z b -mm=*
    – keypress
    Sep 6, 2020 at 17:57
  • 4
    The other tools mentioned on this page pull in a bevy of apparently unrelated dependencies on install, but 7z is self-contained, so a winner for my use case. Sep 10, 2020 at 8:07
  • 1
    to install sudo apt install p7zip-full on ubuntu, or pkg install p7zip on android phone with termux. (package name is not mentioned in the answer)
    – izzulmakin
    Feb 15, 2021 at 8:59
  • 1
    Amazing answer, this was exactly what I needed.
    – Gloat
    Jun 28, 2021 at 19:11
  • Event though it's been longer than a year, this answer still works wonderfully.
    – TheGeeko61
    May 4 at 14:20
16

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.

5
  • 3
    @downvoters please explain :-) Oct 30, 2017 at 17:41
  • 2
    Thanks. I drowned in test options, using build-suite on my first round with phoronix. Jan 16, 2018 at 8:53
  • 1
    it's not in debian 9, but you can still download the .deb from phoronix-test-suite.com/?k=downloads and run sudo apt install ./phoronix-test-suite(...).deb
    – hanshenrik
    Jul 18, 2018 at 11:02
  • 2
    One thing that should be mentioned when describing the PTS is the size of its benchmarks. Running the mentioned pts/cpu benchmark downloads about 3GB of data and uses about 7GB of disk space (in the user's home directory).
    – stefanct
    Jul 23, 2018 at 16:31
  • 4
    Agreed, if you are looking for a simple benchmark then you don't want phoronix-test-suite, it's massive, and keeps asking to download more and more dependencies to run tests. (I'm sure it's very thorough when you actually want this though)
    – Jamie Pate
    Sep 8, 2018 at 1:11
4

If you don't have root permissions (e.g. managed web servers)

Measure single core:

-bash-4.2$ time cat </dev/urandom | head -c 1G | gzip >/dev/null

real    0m43.011s
user    0m42.608s
sys     0m8.819s

Measure all cores:

-bash-4.2$ time cat </dev/urandom | head -c 1G | pigz >/dev/null

real    0m13.870s
user    0m45.988s
sys     0m6.803s

If you already have pv but don't feel like installing special benchmarking software it's even more straightforward

a@a-virtual-machine:~$ pv </dev/urandom | gzip >/dev/null 
 149MiB 0:00:04 [37.5MiB/s]
a@a-virtual-machine:~$ pv </dev/urandom | pigz >/dev/null 
 348MiB 0:00:02 [ 173MiB/s]
1
  • 1
    Awesome, this is what I needed. Thank you!
    – antimirov
    Oct 12 at 20:40

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .