Testing Raspberry PI Storage Speed (SD, USB) with dd

Check my RPI articles in Best Raspberry PI projects article or peppe8o.com home page. Or subscribe my newsletter (top right in this page) to be notified when new projects are available! Also interested to start 3D printing with a cheap budget? Visit my cheap 3D printers list

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:

  • live OS resources usage – if you test a storage media (micro SD for Raspberry PI) where OS is running, then some write/read running processes can reduce measured speed. For this reason I suggest to close all running programs before performing test. It is also better testing speed from a very light OS (like Raspberry PI OS Lite)
  • hardware bottelnecks – speed testing can be affected by hardware limits involved in writing. This means, to be synthetic, that if you test a USB 3.0 stick from a RPI having only USB 2.0 ports will result in speed performances restricted by the slower part (USB 2.0 port).

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.

What we Need

Please find below hardware I used:

Check hardware prices with following links:

Amazon raspberry pi boards box
Amazon raspberry pi Zero W box
Amazon Micro SD box
Amazon Raspberry PI Power Supply box

Step-by-Step Procedure

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 big file (1GB). 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:

  • if = this option enables reading from a file (having “/dev/input.file” absolute or relative path) instead of using stdin
  • of = this option enables writing to a file (having “/path/to/output.file” absolute or relative path) instead of using stdout
  • bs = bytes to read/write at a time (default: 512). BYTES may be followed by the following multiplicative suffixes: c=1, w=2, b=512, kB=1000, K=1024, MB=1000×1000, M=1024×1024, xM=M, GB=1000x1000x1000, G=1024x1024x1024, and so on for T, P, E, Z, Y.
  • count = number of input blocks to copy. N uses same multiplicative suffixes as bs
  • oflag = defines how to write data. Common values are: direct (use direct I/O for data), dsync (use synchronized I/O for data) and sync (like dsync, but also for metadata)

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.

Test Write Speed Performance

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.

Test Read Speed Performance

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.


How useful was this post?

Click on a star to rate it anonymously!

Average rating 5 / 5. Vote count: 1

No votes so far! Be the first to rate this post.

We are sorry that this post was not useful for you!

Let us improve this post!

Tell us how we can improve this post?