Created
August 1, 2021 05:19
-
-
Save hackerb9/5cdaf4df38b8acf225e9056fa850a5f4 to your computer and use it in GitHub Desktop.
A quick hack, no-frills disk speed test. Works with any mountable filesystem (SSD/SATA/IDE/tmpfs...). Just specify the directory you'd like to write the test file to -- defaults to /tmp. Uses 'dd' for a quick test (default is 64MB) and then tries hdparm to run a three second test of direct I/O (no filesystem). It's just a shell script, so this s…
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash -e | |
# Bogus disk speed tester by b9 2016-2021 | |
# Well, not exactly bogus, but overly simplistic. | |
TMPDIR=/tmp # where to write the file | |
COUNT=64 # number of blocks | |
BS=1 # blocksize (in *MEGA*bytes) | |
total=$((COUNT*BS)) | |
[ "$1" ] && TMPDIR="$1" # Usage: bogodisk [dir [count]] | |
[ "$2" ] && COUNT="$2" | |
if [ $(id -u) != 0 ]; then | |
echo "Error: Results are too bogus if caches cannot be dropped." >&2 | |
echo " Please try again as root." >&2 | |
exit 1 | |
fi | |
die() { echo -e "$@" >&2; exit 1; } | |
usage() { echo "Usage: bogodisk [tmpdir [#megabytes]]" >&2; exit 1; } | |
tmpfile=$(mktemp -p $TMPDIR bogodisk.XXXXX) || usage | |
trap 'rm $tmpfile 2>/dev/null' EXIT | |
set -o errexit # Exit immediately if a command fails. | |
set -o pipefail # Pipeline fails if any component fails. | |
export TIMEFORMAT=%3R # Runtime in seconds (3 places of precision) | |
read device fstype < <(df $TMPDIR --output=source,fstype | tail -1) | |
echo -e "Bogodisk 0.0:\tTesting $device ($fstype) with $total MB of data" | |
modelname=$(cat "/sys/class/block/${device#/dev/}/../device/model" 2>&-) \ | |
&& echo -e "\t\t"${modelname#*:} | |
# TEST WRITE SPEED USING dd if=/dev/zero of=$tmpfile | |
echo -ne "\tDropping VM caches...\r" | |
echo 3 > /proc/sys/vm/drop_caches | |
# Preload executables | |
nice ionice dd if=/dev/zero of=/dev/null count=0 2>/dev/null; sync | |
echo -en "\tWriting $total MB ($COUNT blocks of size $BS MB)..." | |
output=$(time ( nice -15 ionice -c 1 \ | |
dd if=/dev/zero of=$tmpfile bs=${BS}M count=$COUNT status=none && \ | |
sync && sync ) 2>&1) \ | |
|| die "\nError: Could not write $total MB to $tmpfile\n$output" | |
echo -e "\r\tWrote $total MB ($COUNT blocks of size $BS MB) in $output seconds" | |
writespeed=$(echo "scale=2; $total/$output" | bc) | |
# TEST READ SPEED USING dd if=$tmpfile of=/dev/null | |
echo -ne "\tDropping VM caches...\r" | |
echo 3 > /proc/sys/vm/drop_caches | |
# Preload executables | |
nice ionice dd if=/dev/zero of=/dev/null count=0 2>/dev/null; sync | |
echo -en "\tReading $total MB ($COUNT blocks of size $BS MB)..." | |
output=$(time ( nice -15 ionice -c 1 \ | |
dd if=$tmpfile of=/dev/null bs=${BS}M count=$COUNT status=none; \ | |
sync; sync ) 2>&1) \ | |
|| die "\nError: Could not read from $tmpfile\n$output" | |
echo -e "\r\tRead $total MB ($COUNT blocks of size $BS MB) in $output seconds" | |
readspeed=$(echo "scale=2; $BS*$COUNT/$output" | bc) | |
printf "Write speed:%'12.2f MB/sec\n" $writespeed | |
printf "Read speed: %'12.2f MB/sec" $readspeed | |
echo -en "\t(...running hdparm...)\r" | |
printf "Read speed: %'12.2f MB/sec" $readspeed | |
if output=$(hdparm -t --direct $device 2>/dev/null | tail -1); then | |
maxread=$(echo ${output##*=}) | |
echo -en "\t(theoretical max $maxread)\r" | |
else | |
echo -en "\t \r" | |
fi | |
printf "Read speed: %'12.2f MB/sec\n" $readspeed | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
bogodisk
This gist is for you if you just want a quick estimate of your disk speed. No fancy programs to install, no baroque interfaces to learn. Runs easily on any typical GNU/Linux system: it's just a shell script.
Must be run as root to write to /proc/sys/vm/drop_caches
Example output
Testing a different disk
Optionally you may increase the data size
Default is 64MB which happens to be a good compromise for current drives: it is small enough for old SATA drives to complete in a reasonable amount of time, yet is big enough that you can get a ballpark estimate of SSD speeds. Note that bash measures execution time in millisecond precision, at best, so you may need to increase the amount of data measured for fast drives or RAM filesystems like tmpfs. To do so, simply specify it (in MB) after the directory name. For example, this uses the default directory (/tmp) but writes 256MB.
BUGS
echo 3 > /proc/sys/vm/drop_caches
.bogodisk
when "disk" implies rotational media, a notion currently about as obsolete as a dodo trained to program in COBOL? Oh well, I also called it "bogo-" back in 2016 because I didn't think timing the speed ofdd
would work very well. However, the years have shown the worth of this useful little script.