Skip to content

Instantly share code, notes, and snippets.

@reox
Last active August 29, 2015 14:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save reox/e110a40f8ab48c44f4b5 to your computer and use it in GitHub Desktop.
Save reox/e110a40f8ab48c44f4b5 to your computer and use it in GitHub Desktop.
testmydisk
#!/bin/bash
# written by reox 2015
# test the read speed of your disk.
# this script will test random access, you can remove the shuf command in the for loop to have linear access too.
# after you run the script, plot the data with your favourite plotting lib.
set +x
set +e
sectors=$(fdisk -l $1 | egrep -o "[0-9]+ sectors" | cut -f 1 -d " ")
size=$(fdisk -l $1 | egrep "Sector size" | cut -d " " -f 7)
# for 512b blocksize, read 64k at once
blocksatonce=65536
# read 128 blocks and skip 65536. So the process will be faster because we do not need to read the whole HD
readatonce=128
echo "Testing Disk, $sectors Sectors, $size Blocksize, reading $blocksatonce Blocks at once. Need $(($sectors/$blocksatonce)) dd commands." 1>&2
echo "offset,seconds,speed,type"
for offset in $(seq 0 $(($blocksatonce)) $(($sectors)) | shuf); do
echo -n $offset,
dd if=$1 skip=$offset ibs=$size count=$readatonce of=/dev/null 2>&1 | tail -n +3 | awk -F ',' '{ print $2 "," $3 ", random"}'
done
for offset in $(seq 0 $(($blocksatonce)) $(($sectors))); do
echo -n $offset,
dd if=$1 skip=$offset ibs=$size count=$readatonce of=/dev/null 2>&1 | tail -n +3 | awk -F ',' '{ print $2 "," $3 ", linear"}'
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment