Skip to content

Instantly share code, notes, and snippets.

@tanasecosminromeo
Last active October 8, 2022 15:04
Show Gist options
  • Save tanasecosminromeo/f9445901b24de37680f5db6ab8677370 to your computer and use it in GitHub Desktop.
Save tanasecosminromeo/f9445901b24de37680f5db6ab8677370 to your computer and use it in GitHub Desktop.
HDD Speed Check
#!/bin/bash
if [ $# -eq 0 ]
then
echo "Usage ./test-hdd.sh /mounted-path-of-hdd [size-in-Mb]"
exit;
fi
actualDisk=$(df $1 | grep dev | cut --d ' ' -f1)
#echo Running hdparm -Tt $actualDisk
#result=$(hdparm -Tt $actualDisk)
testHDD () {
write=$(dd if=/dev/zero of=$1/tempfile bs=1M count=$2 2>&1)
write=$(echo ${write##*s,})
readWcache=$(dd if=$1/tempfile of=/dev/null bs=1M count=$2 2>&1)
readWcache=$(echo ${readWcache##*s,})
/sbin/sysctl -w vm.drop_caches=3 > /dev/null
readNOcache=$(dd if=$1/tempfile of=/dev/null bs=1M count=$2 2>&1)
readNOcache=$(echo ${readNOcache##*s,})
rm -rf $1/tempfile 2>&1
echo -e "$2Mb\t$write\t$readWcache\t$readNOcache"
}
echo "Testing $1 (${actualDisk})"
echo -e "Size\tWrite Speed\tReadWcache\tReadNOcache"
if [ -z "$2" ]
then
testHDD $1 1
testHDD $1 32
testHDD $1 128
testHDD $1 512
else
testHDD $1 $2
fi
#echo Running fio on $1/test-fio
#fio --name=fiotest --filename=$1/test-fio --size=50Mb --rw=randread --bs=8K --direct=1 --numjobs=8 --ioengine=libaio --iodepth=32 --group_reporting --runtime=60 --startdelay=60
@tanasecosminromeo
Copy link
Author

tanasecosminromeo commented Oct 8, 2022

Why

Test different speed of devices / adaptors for a Raspberry Pi 4

Example results

HDD USB3

root@pi4-sdcard:~# ./test-hdd.sh /hdd
Testing /hdd (/dev/sda1)
Size	Write Speed	ReadWcache	ReadNOcache
1Mb	70.1 MB/s	130 MB/s	61.6 MB/s
32Mb	194 MB/s	532 MB/s	239 MB/s
128Mb	42.0 MB/s	533 MB/s	149 MB/s
512Mb	83.0 MB/s	559 MB/s	110 MB/s

SSD USB3

root@pi4-sdcard:~# ./test-hdd.sh /ssd
Testing /ssd (/dev/sda2)
Size	Write Speed	ReadWcache	ReadNOcache
1Mb	52.7 MB/s	111 MB/s	55.6 MB/s
32Mb	172 MB/s	539 MB/s	302 MB/s
128Mb	117 MB/s	551 MB/s	82.8 MB/s
512Mb	40.1 MB/s	555 MB/s	35.1 MB/s

SDCard

root@pi4-sdcard:~# ./test-hdd.sh /home
Testing /home (/dev/root)
Size	Write Speed	ReadWcache	ReadNOcache
1Mb	53.3 MB/s	148 MB/s	55.7 MB/s
32Mb	182 MB/s	531 MB/s	189 MB/s
128Mb	107 MB/s	566 MB/s	101 MB/s
512Mb	38.5 MB/s	546 MB/s	42.8 MB/s

Test specific 10Mb on SDCard

root@pi4-sdcard:~# ./test-hdd.sh /home 10
Testing /home (/dev/root)
Size	Write Speed	ReadWcache	ReadNOcache
10Mb	115 MB/s	416 MB/s	184 MB/s

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment