Monday, March 21

Hard drive benchmarking

Marius Gedminas experimented a bit with hdparm and his results showed no difference in linear disk read rate at the beginning of the disk as compared to at the end. That made me curious. I whipped up a very simple Python script to time some plain reads from the disk and the results are consistent with ones from dd, and with another benchmark of my new drive. Yes, using Python for benchmarking is a stupid idea, and the results are not stable, but I do consistently get almost 40MB/s at the start and no more than 28MB/s at the end of the disk. You can try the script for yourself:

#!/usr/bin/env python

import sys
import time

MiB = 2**20

BLOCKS = 128 # number of megabytes to read at a time
SPACING = 4 * 1024 # number of megabytes to seek forward

if len(sys.argv) < 2:
    print "You must supply a device (e.g., '/dev/hda') as an argument"
    f = open(sys.argv[1], 'r')
except IOError, e:
    if e.errno == 13:
        print ("Permission denied to read the device, you"
               " may need root privileges")

offset = 0
while True:
    start = time.time()
    try: * MiB)
    except IOError:
        break # We probably hit the end of the disk
    for i in range(BLOCKS):
    delta = time.time() - start
    rate = BLOCKS / delta
    print 'Offset: %d GB, read rate: %3.2f MB/s' % (offset / 1024, rate)
    offset += SPACING

print 'Finished.'


shaik sameera said...

Keep in touch whilst functioning from your own home office with out all of the hassle of purchasing or procurment costly office equipment. Debtors are allowed to apply with their a bad credit score background whenever. Wd Hard Disks - Hard Disks, Printers & Monitors

shaik sameera said...

Hi. Cool article. There?s an issue with your website in firefox, and you might want to check this? The browser is the market chief and a good section of people will pass over your great writing because of this problem. Portable Hard Drives at the best price