USB and SSD drive speedtest in Linux

How fast is your USB? How fast is your SSD drive? This seems to be a very common question. I’ve collected and compiled some tests that will help you to do USB and SSD drive speedtest in Linux. When I say speedtest, I am testing read/write speed of USB and SSD drives. This will also tell you if your drives are running at full speed.

USB and SSD drive speedtest in Linux - blackMORE Ops - 11
Image Courtesy: USB Flash Drive ONCHOICE 32GB USB 2.0 Memory Stick LED Thumb Drive Crystal Transparent & Blue Key Shape http://amzn.to/2nmBvR7

The speed of a drive is measured in terms of how much data it can read or write in unit time. The dd command is a simple command line tool that can be used to read and write arbitrary blocks of data to a drive and measure the speed at which the data transfer took place. In this post we shall use the dd command to test read write speed of SSD and USB drives on Linux using the dd command.

The data transfer speed does not depend solely on the drive, but also on the interface it is connected to. For example a USB 2.0 port has a maximum operational speed limit of 35 Mbytes/s, so even if you were to plug a high speed USB 3 pen drive into a USB 2 port, the speed would be capped to the lower limit.

The same applies to SSD. SSD connect via SATA ports which have different versions. Sata 2.0 has a maximum theoretical speed limit of 3Gbits/s which is roughly 375 Mbytes/s. Whereas Sata 3.0 supports twice that speed.

Test Method

Mount the drive and navigate into it from the terminal. Then use the dd command to first write a file using fixed sized blocks. Then read the same file out using the same block site.

The general syntax of the dd command looks like this

dd if=path/to/input_file of=/path/to/output_file bs=block_size count=number_of_blocks

When writing to the drive, we simply read from /dev/zero which is a source of infinite useless bytes. And when read from the drive, we read the file written earlier and send it to /dev/null which is nowhere. In the whole process, dd keeps track of the speed with which the transfer takes place and reports it.

TEST Hard Disk READ Speed Using dd Command

The file tempfile, that has just been created by the previous command, was cached in a buffer and its read speed is much higher then the real read speed directly from the hard drive. To get the real speed, we have to clear cache.

Run the following command to find out the READ Speed From Buffer :

$ dd if=tempfile of=/dev/null bs=1M count=1024
1024+0 records in
1024+0 records out
1073741824 bytes (1.1 GB) copied, 0.159273 s, 6.7 GB/s

Clear The Linux Cache and accurately measure the Real READ Speed directly from the hard drive :

$ sudo /sbin/sysctl -w vm.drop_caches=3
vm.drop_caches = 3
$ dd if=tempfile of=/dev/null bs=1M count=1024
1024+0 records in
1024+0 records out
1073741824 bytes (1.1 GB) copied, 2.27431 s, 472 MB/s

TEST Hard Disk WRITE Speed Using dd Command

Run the following command to test the WRITE Speed of a hard disk :

$ sync; dd if=/dev/zero of=tempfile bs=1M count=1024; sync
1024+0 records in
1024+0 records out
1073741824 bytes (1.1 GB) copied, 3.28696 s, 327 MB/s

SSD

The SSD that we are using is a “Samsung Evo 120GB” SSD. It is a beginner level SSD that comes within a decent budget and is also my first SSD. It is also one of the best performing SSD’s in the market.

Now lets start with the instructions to test read write speed of SSD. Our SSD is connected to a SATA 2.0 port for this test.

Write speed

Lets first write to the ssd

$ dd if=/dev/zero of=./largefile bs=1M count=1024
1024+0 records in
1024+0 records out
1073741824 bytes (1.1 GB) copied, 4.82364 s, 223 MB/s

Block size is actually quite large. You can try with smaller sizes like 64k or even 4k.

Read speed

Now read back the same file. However, first clear the memory cache to ensure that the file is actually read from drive.

Run the following command to clear the memory cache

$ sudo sh -c "sync && echo 3 > /proc/sys/vm/drop_caches"

Now read the file

$ dd if=./largefile of=/dev/null bs=4k
165118+0 records in
165118+0 records out
676323328 bytes (676 MB) copied, 3.0114 s, 225 MB/s

USB

In this test we shall measure the read and write speed of ordinary USB/PEN drives. The drives are plugged to standard USB 2 ports. The first one is a Sony 4GB USB drive and the second is a strontium 16GB drive.

First plug the drive into the port and mount it, so that it is readable. Then navigate into the mount directory from the command line.

TEST Read/Write Speed of an External Hard Drive

To check the performance of some External HDD, USB Flash Drive or any other removable device or remote file-system, simply access the mount point and repeat the above commands.

Or you can replace tempfile with the path to your mount point e.g. :

$ sync; dd if=/dev/zero of=/media/user/MyUSB/tempfile bs=1M count=1024; sync

All above commands use the temporary file tempfile. Don’t forget to delete it when you complete the tests.

Sony 4GB – Write

In this test, the dd command is used to write 10,000 chunks of 8 Kbyte each to a single file on the drive.

# dd if=/dev/zero of=./largefile bs=8k count=10000
10000+0 records in
10000+0 records out
81920000 bytes (82 MB) copied, 11.0626 s, 7.4 MB/s

So the write speed is around 7.5 MBytes/s. This is a low figure.

Sony 4GB – Read

The same file is read back to test the read speed. Run the following command to clear the memory cache

$ sudo sh -c "sync && echo 3 > /proc/sys/vm/drop_caches"

Now read the file using the dd command

# dd if=./largefile of=/dev/null bs=8k
8000+0 records in
8000+0 records out
65536000 bytes (66 MB) copied, 2.65218 s, 24.7 MB/s

The read speed comes out around 25 Mbytes/s which is a more or less the standard for cheap usb drives.

USB 2.0 has a theoretical maximum signaling rate of 480 Mbits/s or 60 Mbytes/s. However due to various constraints the maximum throughput is restricted to around 280 Mbit/s or 35 Mbytes/s. Beyond this the actual speed achieved depends on the quality of the pen drives and other factors too.

And the above USB drive was plugged inside a USB 2.0 port and it achieved a read speed of 24.7 MBytes/s which is not very bad. But the write speed lags much behind

Now lets do the same test with a Strontium 16GB drive. Strontium is another very cheapy brand, although USB drives are reliable.

Strontium 16GB write speed

# dd if=/dev/zero of=./largefile bs=64k count=1000
1000+0 records in
1000+0 records out
65536000 bytes (66 MB) copied, 8.3834 s, 7.8 MB/s

Strontium 16gb read speed

# sudo sh -c "sync && echo 3 > /proc/sys/vm/drop_caches"

# dd if=./largefile of=/dev/null bs=8k
8000+0 records in
8000+0 records out
65536000 bytes (66 MB) copied, 2.90366 s, 22.6 MB/s

The read speed is lower than the Sony drive.

Check Hard Disk Performance Using hdparm

hdparm – is a Linux utility that allows to quickly find out the READ speed of a hard drive.

Install hdparm depending on your Linux distribution.

On Linux Mint, Ubuntu, Debian :

$ sudo apt-get install hdparm

On CentOS, RHEL :

$ sudo yum install hdparm

Run hdparm as follows, to measure the READ speed of a hard drive device /dev/sda :

$ sudo hdparm -Tt /dev/sda
/dev/sda:
 Timing cached reads:   16924 MB in  2.00 seconds = 8469.95 MB/sec
 Timing buffered disk reads: 1386 MB in  3.00 seconds = 461.50 MB/sec

To get the accurate read/write speed, you should repeat the below tests several times (usually 3-5) and take the average result.

Resources

Leave a Reply

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