107

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.

fatso
  • 1,071
  • 2
  • 8
  • 3
  • 4
    There is [Geekbench](http://www.primatelabs.com/geekbench/) which can compare CPUs (there are already existing test results for the [e7500](http://browser.primatelabs.com/geekbench3/search?q=e7500) and the [q9400](http://browser.primatelabs.com/geekbench3/search?q=q9400), though many are in drastically different setups, which will have different bus speeds etc. – Wilf Jun 10 '15 at 10:18

5 Answers5

130

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
randers
  • 271
  • 3
  • 13
Raja G
  • 100,643
  • 105
  • 254
  • 328
  • 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 '16 at 17:29
  • 22
    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 '16 at 17:31
  • 3
    Is there a place to compare the output to get relative performance? – jjxtra Sep 13 '19 at 22:33
  • @jjxtra that's exactly the problem, all these benchmarks are close to completely useless, I could easily write my own little stress test without any problem but there is no reference (or you don't easily find it, which makes any benchmark trivial). – meow Nov 19 '19 at 12:50
  • I've just resorted to https://www.cpubenchmark.net/ to get ballpark figures :) – jjxtra Nov 19 '19 at 16:03
  • 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 '20 at 22:30
  • 3
    @MestreLion `WARNING: --num-threads is deprecated, use --threads instead` – Madacol Sep 03 '20 at 21:33
  • @Madacol: Yes, it seems `sysbench` changed its CLI interface since 2016 when I made the comment. `--threads` is preferred now, thanks for pointing it out – MestreLion Sep 04 '20 at 19:17
  • Keep in mind that `sysbench` isn't really comparable between systems: https://github.com/akopytov/sysbench/issues/469 – kiler129 Mar 18 '23 at 23:16
40

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  
yprez
  • 863
  • 8
  • 15
Colin Ian King
  • 18,370
  • 3
  • 59
  • 70
  • 3
    " Unable to locate package stress-ng!" – Ehsan M. Kermani Feb 05 '16 at 00: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 – Colin Ian King Mar 03 '16 at 16:56
  • @EhsanM.Kermani : it's available in the repositories only from Ubuntu 15.14 onwards (and to 14.04 using the *backports* repository). See http://packages.ubuntu.com/search?searchon=names&suite=all&section=all&keywords=stress-ng – MestreLion Mar 22 '16 at 17:36
  • "`--perf`: Unknown option (364)". stress-ng version 0.07.11 – rustyx Feb 10 '17 at 21:23
  • I have newer versions that are built for older releases in my ppa: ppa:colin-king/white – Colin Ian King Feb 10 '17 at 23:15
  • http://kernel.ubuntu.com/~cking/stress-ng/ – Colin Ian King Sep 16 '17 at 10:48
  • 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 Franzl Feb 23 '18 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. – Colin Ian King Feb 23 '18 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 08 '19 at 14:40
  • Wow. Running `sudo stress-ng` makes my dell server reboot. No bueno. – Leopd Apr 02 '21 at 21:33
  • Also rebooted my ubuntu hetzner server! So use with caution and not on production hardware – yvess Mar 27 '23 at 05:25
33

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
CenterOrbit
  • 587
  • 5
  • 5
15

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.

Ciro Santilli OurBigBook.com
  • 26,663
  • 14
  • 108
  • 107
  • 3
    @downvoters please explain :-) – Ciro Santilli OurBigBook.com Oct 30 '17 at 17:41
  • 2
    Thanks. I drowned in test options, using build-suite on my first round with phoronix. – andersoyvind Jan 16 '18 at 08:53
  • 1
    it's not in debian 9, but you can still download the .deb from https://www.phoronix-test-suite.com/?k=downloads and run `sudo apt install ./phoronix-test-suite(...).deb` – hanshenrik Jul 18 '18 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 '18 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 08 '18 at 01:11
0

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]