Benchmarking Linux systems with command line tools

Benchmarking and  stress testing is sometime necessary to optimize system performance and remove system bottlenecks caused by hardware. In a Linux system , this could be done easily with few basic command line tools.

There are many all in one dedicated benchmarking tool with a pretty GUI available for Linux. But here we are focusing on simple command line tools only and going to test the followings listed bellow.

  • CPU stress testing and benchmarking.
  • Hard drive I/O performance testing.
  • Network performance and speed testing.
  • OpenSSL performance testing.
  • RAM speed testing.

Have a look at this guide for a detailed GPU benchmarking and stress testing.


1. CPU Benchmark and stress testing

Prime number calculation test within a given range with sysbench,

 sysbench --test=cpu --num-threads=4 --cpu-max-prime=9999 run 

this command will calculate all prime numbers within 9999, change the number 9999 if you wish.

Integer calculation performance test with  one-line command

 time $(i=0; while (( i < 9999999 )); do (( i ++ )); done) 

this will return the the time required to crunch the integers between 0 to 9999999.

real   0m47.354s
user   0m47.328s
sys    0m0.000s

Single threaded CPU stress testing

 md5sum /dev/urandom 

the /dev/urandom file is a special type of device file, which returns random junk characters endlessly, so calculating md5 hash of /dev/urandom is basically  stressing the CPU.

Multi threaded CPU stress testing

This command is to impose a multi threaded load on the CPU for 5minuite,

 stress --cpu 4 --timeout 300s 

change  –cpu 4  value according to your system, if you have a quad core 8 threaded CPU, then use –cpu 8 .


2. Hard drive I/O performance testing

Hard drive I/O performance have a great impact on Linux system performance and user experience. Simply faster HDD means better user experience and in most cases, hard drive I/O speed is more important than CPU and RAM speed.

HDD raw read speed test

A vary simple raw hard drive read speed could be determined with cat and pipebench . This command requires root privilege, so run it as a root user or use sudo.

cat /dev/sda3 | pipebench -q > /dev/null

HDD file write speed test with dd

 dd bs=16k count=102400 oflag=direct if=/dev/zero of=test_data 

This will create a file of round 1.6 GB containing only zeros, at the present directory and will give you an overview of your HDD write speed.

HDD file read speed test with dd

Now we will use the test_data file created in the above step to determine HDD read speed.

 dd bs=16K count=102400 iflag=direct if=test_data of=/dev/null 

This command will read the test_data file and throug the data to a black hole like special device file, /dev/null.

Direct drive read speed test with hdparm

 sudo hdparm -t /dev/sda 

hdparm read speed test

This test returns timing buffered disk read speed and this result could be assumed as the fastest disk read speed.

note: In Linux, it is common that native filesystems (ext4, btrfs, xfs etc.) always tends to perform better than other third party filesystems like Windows NTFS or Mac HFS+ .


3. Network performance and speed testing

Network interface throughput measurement and benchmarking is very common for networking devices like routers, bridges, hubs etc. Everyone want the best speed out of their network, so it’s necessary to benchmark and optimize the network.

Simple network throughput measurement with iperf .

  1. First start a iperf server in the server machine,

     iperf -s -p 8000 

    this will start a iperf in server mode, which binds port 8080 with all available network interfaces.

  2. Now connect to that server with iperf as client, just find the correct server IP address and run the command bellow
    iperf -c -p 8000

    this will give you overview of your networks tcp connection throughput speed.iperf network speed test linux


Network speed test with ncmeter

Ncmeter is a simple bash shell script which uses netcat-traditional to measure data throughput of a network. This scripts is a part of the netcat-traditional package in Debian based distros, located at the /usr/share/doc/netcat-traditional/examples/contrib folder. Copy that script to /usr/local/bin , make it executable with chmod +x and then run the script.

cp /usr/share/doc/netcat-traditional/examples/contrib/ncmeter ~/

chmod +x ~/ncmeter

./ncmeter --help  # show available options

Start the ncmeter in server mode


which binds all available network interfaces with port 23457.

Open up a new terminal or new tab then run the following command.

./ncmeter 256M

Replace the IP with your ncmeter servers IP.

network benchmark linux ncmeter


4. OpenSSL performance testing

This test basically means how fast the CPU can calculate cryptographic hashes like md5, sha1, aes, rsa etc. etc. This test is also important for networking devices like routers, bridges, hubs etc.

OpenSSL benchmarking could be done easily with the commands bellow.

 openssl speed des des-ede3 dsa2048 hmac idea-cbc md5 

This performance varies greatly if there is any hardware cryptographic accelerator present in the CPU, for more detail see the openssl man page and openssl website.


5. RAM speed testing

There is no direct method to benchmark a RAM and generally RAM speed  denotes RAM clock speed. It is unnecessary to do such testing but this may be considered as an experiment.

tmpfs is a RAM based super fast file system, something like a ramdisk, so by doing a read write speed test on a tmpfs mounted folder will give a rough idea about RAM speed. So, lets have a look at commands bellow.

mkdir RAM_test

sudo mount tmpfs -t tmpfs RAM_test/  # mount the tmpfs filesystem

cd RAM_test

dd if=/dev/zero of=data_tmp bs=1M count=512  # write to RAM test

dd if=data_tmp of=/dev/null bs=1M count=512

Look at the result ! It’s incredibly fast ! I achieved around 2.8 GB/s write speed and 3.8 GB/s read speed with a 4GB 1333 MHz DDR3 RAM module. I don’t have any system with a modern 1600 MHz DDR3L RAM or with a 2100 MHz DDR4 RAM, if you have one please do this test share your experience.


So, that’s it, simple benchmark test in Linux, this will give you a rough overview of your system performance. Though benchmarking results could vary test by test as system performance depends upon many things like currently running applications, background tasks even on ambient temperature. This methods should work perfectly on wide range of GNU/Linux or UNIX distributions. If you have any further question, feel free to ask it and don’t forget to share this tutorial with your friends.

Leave a Reply

Your email address will not be published. Required fields are marked *