Test HDD, SSD, and USB Read/Write Speeds with dd
I have found a fancy way to test the speeds of my media devices by using the dd tool. For those that don’t know what the dd command stands for or does, Disk/data Duplicator is a tool that was used in the old BSD/AT&T days but still has great functionality today.
Mostly dd is used for writing a .iso to a USB to be used to boot into a Linux distro or what have you. It can also be used to copy a block file or an entire disk to another disk or partition, which is kinda what we are going to be doing in this speed test example today.
Write Speed Test
In this example, say we have a NVMe drive labeled as /dev/nvme0n1 and our root filesystem in /dev/nvme0n1p2. To test the speeds of our NVMe device we would first need to run:
cd /tmp
sync; dd if=/dev/zero of=tempfile bs=1M count=1024; sync
This will create a 1 GB file called tempfile in the /tmp directory. The sync commands are meant to force the TTY to not redirect the console to input mode before it finishes creating the new tempfile completely.
This similar to how a USB drive on Windows works and perhaps even on Linux, where the data copied to the USB drive might show that the send was complete but in fact the OS is still running it in the background. This is why it is important to make sure you eject properly after doing any kind of transfer of data.
Also what was done was we input a file from the /dev/zero folder which basically stuffs the output file with zeros until it fills it at 1 MB size 1024 times which equals to 1 GB. You can alternatively use /dev/urandom to fill the file with random junk but zeros will also work.
In my case the 1 GB created file took 0.230744 seconds and was created at 4.7 GB/s.

Most often you will find that writing to a disk is faster than reading from a disk as shown in the next example.
Read Speed Test
Now for reading the file. In most cases reading a file is slower especially if it is a mechanical spinning rust drive, since the head needs to seek for the metadata first then reference that to find where the file is in relation to how the metadata tells it to go.
Similar to above we will run dd but we don’t need the sync commands as the device in question is not being written to.
dd if=tempfile of=/dev/null bs=1M count=1024
Due to how NVMe and SSDs work the read times will be faster than a spinning-rust drive but also due to how caching works reading while the data is still warm may provide you with faster speeds than writing. I will show both examples. One on my NVMe and one on my server running on a HDD.

My NMVe drive is super fast and reads it faster than a blink of the eye. On a HDD the speeds are slower but overall it didn’t take much time to read and write a 1 GB file either.

I further tested the HDD by writing a 10 GB file then immediately reading it which again took less time then writing it. Finally I read the 1 GB file again as it was no longer cached in the HDD and BAM… it took six times longer to reading it cold then reading it warm.

Results will vary as you play around with your drives but this example show how to verify what your system is capable of doing in a perfect scenario. Various things will offset these numbers like CPU load, HDD load, etc.