In modern computing, measuring a CPU's performance goes beyond simple clock speed. Modern CPUs have diverse architectures and optimizations, which means assessing their real-world performance requires precise benchmarks. This is particularly important in Linux environments, where different tasks demand different CPU capabilities.
Benchmarking tools in Linux are used to evaluate a CPU's performance by running specific tests. These tools execute tasks on the CPU and measure how quickly they are completed. While synthetic benchmarks provide a controlled environment for testing, real-world benchmarks give insights into how the CPU performs under typical workloads.
Among various benchmarking tools available for Linux, sysbench is a widely-used option. It is included in the default package repositories of most Linux distributions, such as Ubuntu. Sysbench provides a reliable way to measure the performance of your CPU under different conditions, making it a valuable tool for any Linux user.
Steps to benchmark CPU performance in Linux:
- Open the terminal on your Linux system.
- Install the sysbench package from your distribution's package manager.
$ sudo apt update && sudo apt install --assume-yes sysbench # Ubuntu and variants > sudo zypper refresh && sudo zypper install --skip-interactive sysbench $ sudo dnf install sysbench
- Identify the number of CPU cores and threads in your system using the lscpu command.
$ lscpu | grep "^CPU.s\|^Thread.s" CPU(s): 8 Thread(s) per core: 2
- Run a test to measure the performance of a single CPU core.
$ sysbench cpu run sysbench 1.0.20 (using system LuaJIT 2.1.0-beta3) Running the test with following options: Number of threads: 1 Initializing random number generator from current time Prime numbers limit: 10000 Initializing worker threads... Threads started! CPU speed: events per second: 8651.52 General statistics: total time: 10.0002s total number of events: 86521 Latency (ms): min: 0.11 avg: 0.12 max: 1.21 95th percentile: 0.12 sum: 9987.69 Threads fairness: events (avg/stddev): 86521.0000/0.00 execution time (avg/stddev): 9.9877/0.00
This command tests the speed of a single CPU core by calculating prime numbers up to a specified limit.
- Run a test to measure the performance of multiple CPU cores.
$ sysbench cpu --threads=16 run sysbench 1.0.20 (using system LuaJIT 2.1.0-beta3) Running the test with following options: Number of threads: 16 Initializing random number generator from current time Prime numbers limit: 10000 Initializing worker threads... Threads started! CPU speed: events per second: 16608.45 General statistics: total time: 10.0006s total number of events: 166101 Latency (ms): min: 0.11 avg: 0.96 max: 68.15 95th percentile: 0.13 sum: 159504.98 Threads fairness: events (avg/stddev): 10381.3125/69.32 execution time (avg/stddev): 9.9691/0.02
- Conduct a prolonged benchmark to simulate sustained CPU load over time.
$ sysbench cpu --threads=16 --time=60 run sysbench 1.0.20 (using system LuaJIT 2.1.0-beta3) Running the test with following options: Number of threads: 16 Initializing random number generator from current time Prime numbers limit: 10000 Initializing worker threads... Threads started! CPU speed: events per second: 16649.33 General statistics: total time: 60.0007s total number of events: 998978 Latency (ms): min: 0.11 avg: 0.96 max: 101.62 95th percentile: 0.13 sum: 958670.12 Threads fairness: events (avg/stddev): 62436.1250/236.58 execution time (avg/stddev): 59.9169/0.03
Longer benchmarks can cause the CPU to hit and emulate frequency scaling and thermal limitations.
- Adjust sysbench options to refine your benchmark tests as needed.
$ sysbench --help Usage: sysbench [options]... [testname] [command] Commands implemented by most tests: prepare run cleanup help General options: --threads=N number of threads to use [1] --events=N limit for total number of events [0] --time=N limit for total execution time in seconds [10] --forced-shutdown=STRING number of seconds to wait after the --time limit before forcing shutdown, or 'off' to disable [off] --thread-stack-size=SIZE size of stack per thread [64K] --rate=N average transactions rate. 0 for unlimited rate [0] --report-interval=N periodically report intermediate statistics with a specified interval in seconds. 0 disables intermediate reports [0] --report-checkpoints=[LIST,...] dump full statistics and reset all counters at specified points in time. The argument is a list of comma-separated values representing the amount of time in seconds elapsed from start of test when report checkpoint(s) must be performed. Report checkpoints are off by default. [] --debug[=on|off] print more debugging info [off] --validate[=on|off] perform validation checks where possible [off] --help[=on|off] print help and exit [off] --version[=on|off] print version and exit [off] --config-file=FILENAME File containing command line options --tx-rate=N deprecated alias for --rate [0] --max-requests=N deprecated alias for --events [0] --max-time=N deprecated alias for --time [0] --num-threads=N deprecated alias for --threads [1] Pseudo-Random Numbers Generator options: --rand-type=STRING random numbers distribution {uniform,gaussian,special,pareto} [special] --rand-spec-iter=N number of iterations used for numbers generation [12] --rand-spec-pct=N percentage of values to be treated as 'special' (for special distribution) [1] --rand-spec-res=N percentage of 'special' values to use (for special distribution) [75] --rand-seed=N seed for random number generator. When 0, the current time is used as a RNG seed. [0] --rand-pareto-h=N parameter h for pareto distribution [0.2] Log options: --verbosity=N verbosity level {5 - debug, 0 - only critical messages} [3] --percentile=N percentile to calculate in latency statistics (1-100). Use the special value of 0 to disable percentile calculations [95] --histogram[=on|off] print latency histogram in report [off] General database options: --db-driver=STRING specifies database driver to use ('help' to get list of available drivers) [mysql] --db-ps-mode=STRING prepared statements usage mode {auto, disable} [auto] --db-debug[=on|off] print database-specific debug information [off] Compiled-in database drivers: mysql - MySQL driver pgsql - PostgreSQL driver mysql options: --mysql-host=[LIST,...] MySQL server host [localhost] --mysql-port=[LIST,...] MySQL server port [3306] --mysql-socket=[LIST,...] MySQL socket --mysql-user=STRING MySQL user [sbtest] --mysql-password=STRING MySQL password [] --mysql-db=STRING MySQL database name [sbtest] --mysql-ssl[=on|off] use SSL connections, if available in the client library [off] --mysql-ssl-cipher=STRING use specific cipher for SSL connections [] --mysql-compression[=on|off] use compression, if available in the client library [off] --mysql-debug[=on|off] trace all client library calls [off] --mysql-ignore-errors=[LIST,...] list of errors to ignore, or "all" [1213,1020,1205] --mysql-dry-run[=on|off] Dry run, pretend that all MySQL client API calls are successful without executing them [off] pgsql options: --pgsql-host=STRING PostgreSQL server host [localhost] --pgsql-port=N PostgreSQL server port [5432] --pgsql-user=STRING PostgreSQL user [sbtest] --pgsql-password=STRING PostgreSQL password [] --pgsql-db=STRING PostgreSQL database name [sbtest] Compiled-in tests: fileio - File I/O test cpu - CPU performance test memory - Memory functions speed test threads - Threads subsystem performance test mutex - Mutex performance test See 'sysbench <testname> help' for a list of options for each test.
Mohd Shakir Zakaria is an experienced cloud architect with a strong development and open-source advocacy background. He boasts multiple certifications in AWS, Red Hat, VMware, ITIL, and Linux, underscoring his expertise in cloud architecture and system administration.
Comment anonymously. Login not required.