Skip to content

Instantly share code, notes, and snippets.

@kaniblu
Created August 7, 2019 12:18
Show Gist options
  • Save kaniblu/9625ea09f063e7078a61863865b9416d to your computer and use it in GitHub Desktop.
Save kaniblu/9625ea09f063e7078a61863865b9416d to your computer and use it in GitHub Desktop.
A simple script for benchmarking disk I/O speeds. Run this script with `sudo` at a directory that resides in the disk.
#!/bin/bash
if [ "$EUID" -ne 0 ]
then
echo "root privilege is required. re-run this script with 'sudo'." >&2
exit 1
fi
TEMP_PATH=$(tempfile -d $(pwd))
function clear_cache {
/sbin/sysctl -w vm.drop_caches=3 > /dev/null 2>&1
}
function test_write {
clear_cache
sync
dd if=/dev/zero of=$TEMP_PATH bs=5M count=256
sync
}
function test_read {
clear_cache
sync
dd if=$TEMP_PATH of=/dev/null bs=5M count=256
sync
}
echo -e "measuring write speed...\c"
WRITE_SPEED=$(test_write 2>&1 | grep copied | rev | cut -d ' ' -f 1-2 | rev)
echo -e "\rmeasuring write speed... $WRITE_SPEED"
echo -e "measuring read speed...\c"
READ_SPEED=$(test_read 2>&1 | grep copied | rev | cut -d ' ' -f 1-2 | rev)
echo -e "\rmeasuring read speed... $READ_SPEED"
rm -rf $TEMP_PATH
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment