Raspberry PI performaces are deeply impacted from storage speed.
To figure it out, you can imagine for example your SD card as a PC hard disk. Changing mechanical HDD with an SDD storage will drastically increase operating system performances as OS can read and write faster programs code and files.
For this reason I refer in my tricks to improve Raspberry PI performances also using a fast SD card.
The best way to test effective write/read speed is writing and reading on it. But you should consider results from this test indicative (even really near to real speed) because affected from some factors:
For this test I’ll use “dd” terminal command. a common utility for Unix and Unix-like operating systems (already available in all Raspberry PI OS distributions) whose primary purpose is to convert and copy files.
In this tutorial I’m going to show you how to test storage speed (SD card or any USB storage) from terminal. This guide will use a Raspberry PI Zero W, but works with all Raspberry PI boards.
Please find below hardware I used:
Check hardware prices with following links:
If not already done, please install Raspberry PI OS Lite (for a headless, fast OS) or install Raspberry PI OS Desktop (in this case, using its internal terminal).
Eve not strictly needed, I always suggest to make your OS up-to-date. From terminal:
sudo apt update -y && sudo apt upgrade -y
In following steps, we’ll first test writing speed by creating a dummy file (100MB). You can change this size according to you preferences. Greater files will get more precise results, but will require more time.
After this, we’ll get reading speed by reading the same file.
We are going to use following dd command:
dd if=/dev/input.file of=/path/to/output.file bs=BYTES count=N oflag=FLAGS
Options are explained in following list:
Important note: when using a “pure” device path in of option (such as /dev/sda) the data stored there will be lost. For that reason, you should only use empty storage media or specify file name to write, unless you know what you are doing.
Write speed test will use a dummy source to generate bytes to write on phisical file on storage. The /dev/zero is used as source. It is a special device file which generates a continuous stream of null characters (zero-value bytes). If used as destination path, it accepts and discards all data written to it.
For write speed test purposes, at least 100MB of free storage space required (creating 5 blocks of 20MB each one copied inside the same output file).
You can run this test by using following terminal command:
dd if=/dev/zero of=./speedTestFile bs=20M count=5 oflag=direct
This will generate a similar output to following one:
pi@raspberrypi:~ $ dd if=/dev/zero of=./speedTestFile bs=20M count=5 oflag=direct
5+0 records in
5+0 records out
104857600 bytes (105 MB, 100 MiB) copied, 8.12716 s, 12.9 MB/s
Last row reports measured time spent and average speed during copy operations. Assuming /dev/zero read time irrelevant compared to storage performances, these values are the write performance results.
You can also change bs and count values to perform tests in changing conditions, taking care to have enough disk space for each test.
Read speed test will use previously generated file as source, sending data to /dev/zero virtual device file. This will require dsync value for oflag option instead of direct.
Terminal command to perform read test will be the following:
dd if=./speedTestFile of=/dev/zero bs=20M count=5 oflag=dsync
Resulting in a final report similar to following one:
pi@raspberrypi:~ $ dd if=./speedTestFile of=/dev/zero bs=20M count=5 oflag=dsync
5+0 records in
5+0 records out
104857600 bytes (105 MB, 100 MiB) copied, 4.50321 s, 23.3 MB/s
Last row reports opertion time spent and average speed. Again, assuming write speed to /dev/zero irrelevant compared to storage performances, measured speed will be likely near your storage read performances.
Little curiosity. Running again read test will produce different speed results:
pi@raspberrypi:~ $ dd if=./speedTestFile of=/dev/zero bs=20M count=5 oflag=dsync
5+0 records in
5+0 records out
104857600 bytes (105 MB, 100 MiB) copied, 0.447308 s, 234 MB/s
Second test should give different performances because this time your OS knows that the same file have been read and is available and cached in RAM (without changes from storage copy), so uses RAM copy instead of storage one. If you regenerate speedTestFile again, you will have a “new” file (even if with same name) and read test will go back to first reading speed.
Enjoy!
In this tutorial, we will use two Arduino Uno to demonstrate the Serial Peripheral Interface…
In this tutorial, we will be making an automatic irrigation system (AIS) with Arduino and…
This tutorial will show you how to use Python Virtual Environment with Raspberry PI computer…
This tutorial will show you how to get betting odds with Raspberry PI by using…
This tutorial will show you how to perform the backup of Raspberry PI (computer board)…
This tutorial will show you how to install Honeygain on a Raspberry PI computer board…
View Comments
Hello, thanks for the procedure - its worked well with my new external SamsungT5 portable USB3 drive.
Note: At the beginning of the article you wrote that you want to create and test with a 1GB file - but later on you write and read 20MB x 5 = 100 MiB.
Yes, you are right. Sorry, this was my fault. Post updated accordingly.
Many thanks
Hey! I ran the speed test command and it returned the "records in" and "records out" values, but the last line that shows the actual speed did not appear. What could be wrong with my setup? Thanks!
This is really strange. You can try appending at the end of command the option "status=progress". What is your OS? Is it updated and upgraded?