Using Command Line to benchmark disks

As a ServiceDesk and OS X engineer you often find that you need to benchmark your disk to see if the performance has deteriorated. There are a large number of disk benchmark applications out there, which are all effective at what they do.

If, however, you are stuck without the ability to download any of those applications or need a quick and easy way to view the read/write performance of your disk drive, try this.

To test the write performance of your primary drive, run the following on terminal:

write=$(dd if=/dev/zero bs=2048k of=tstfile count=1024 2>&1 | grep sec | awk '{print $1 / 1024 / 1024 / $5, "MB/sec" }')

echo $write

This will display your write disk performance and display it in MB/sec.

To test the write performance of your primary drive run the following on terminal:

read=$(dd if=tstfile bs=2048k of=/dev/null count=1024 2>&1 | grep sec | awk '{print $1 / 1024 / 1024 / $5, "MB/sec" }')

echo $read

To test the read performance of your primary drive, you will need to run:

Purge

command in order to clear the testfile from RAM. If you don’t, you will notice really high scores because the system will be reading from RAM and not from disk.

So, here’s a script to do that for you:

#!/bin/bash
echo "---------------------"
echo "Write Test Running. Please Wait..."
write=$(dd if=/dev/zero bs=2048k of=tstfile count=1024 2>&1 | grep sec | awk '{print $1 / 1024 / 1024 / $5, "MB/sec" }')
purge
echo ""
echo "Read Test Running. Please Wait..."
read=$(dd if=tstfile bs=2048k of=/dev/null count=1024 2>&1 | grep sec | awk '{print $1 / 1024 / 1024 / $5, "MB/sec" }')
clear
echo ""
echo "Read Speed is: $read"
echo "Write Speed is: $write"
echo "---------------------"
echo "Cleaning up. Please Wait..."
purge
rm tstfile
echo ""
exit 0

Leave a Reply

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