# Hard Drive Speed (read & write)

## Recommended Posts

Hi all

Im busy sorting out some parts of a script that deal with speed like processor and memory etc etc

the one i cant find on the forum or in the helpfile is hard drive speed?

I need the speed to give an estimation of time for the size of backup that will be transfering

so a function or something that gives a variable so i can feed it to an equation that its needed for

Does such a thing exist??

Chimaera

Edited by Chimaera

If Ive just helped you ... miracles do happen. Chimaera

##### Share on other sites

all sorts of stats available through WMI. Of course, you could always calculate your own as you go.

Lots of different metrics for estimating file transfer times; % of bytes, % of files; all pretty much a roll of the dice, esp. if you can't rely on constant b/w, latency, cpu/disk utilizations , etc..

Reading the help file before you post... Not only will it make you look smarter, it will make you smarter.

##### Share on other sites

I asked the same question before.

Did a little searching on MSDN about WMI and concluded Win32_DiskDrive / Win32_LogicalDisk don't obtain the Disk Speed. I also did a little bit of "Internet Searching" and found an example on Stackflow in C# (not AutoIt I know!)

Plus, have a look at by Ascend4nt

Edited by guinness

##### Share on other sites

\$wbemFlagReturnImmediately = 0x10
\$wbemFlagForwardOnly = 0x20
\$colItems = ""
\$strComputer = "localhost"

\$Output=""
\$Output &= "Computer: " & \$strComputer  & @CRLF
\$Output &= "==========================================" & @CRLF
\$objWMIService = ObjGet("winmgmts:\\" & \$strComputer & "\root\CIMV2")
\$colItems = \$objWMIService.ExecQuery("SELECT * FROM Win32_PerfRawData_PerfDisk_PhysicalDisk", "WQL", _
\$wbemFlagReturnImmediately + \$wbemFlagForwardOnly)

If IsObj(\$colItems) then
For \$objItem In \$colItems
\$Output &= "AvgDiskBytesPerTransfer: " & \$objItem.AvgDiskBytesPerTransfer & @CRLF
\$Output &= "AvgDiskBytesPerTransfer_Base: " & \$objItem.AvgDiskBytesPerTransfer_Base & @CRLF
\$Output &= "AvgDiskBytesPerWrite: " & \$objItem.AvgDiskBytesPerWrite & @CRLF
\$Output &= "AvgDiskBytesPerWrite_Base: " & \$objItem.AvgDiskBytesPerWrite_Base & @CRLF
\$Output &= "AvgDiskQueueLength: " & \$objItem.AvgDiskQueueLength & @CRLF
\$Output &= "AvgDisksecPerTransfer: " & \$objItem.AvgDisksecPerTransfer & @CRLF
\$Output &= "AvgDisksecPerTransfer_Base: " & \$objItem.AvgDisksecPerTransfer_Base & @CRLF
\$Output &= "AvgDisksecPerWrite: " & \$objItem.AvgDisksecPerWrite & @CRLF
\$Output &= "AvgDisksecPerWrite_Base: " & \$objItem.AvgDisksecPerWrite_Base & @CRLF
\$Output &= "AvgDiskWriteQueueLength: " & \$objItem.AvgDiskWriteQueueLength & @CRLF
\$Output &= "Caption: " & \$objItem.Caption & @CRLF
\$Output &= "CurrentDiskQueueLength: " & \$objItem.CurrentDiskQueueLength & @CRLF
\$Output &= "Description: " & \$objItem.Description & @CRLF
\$Output &= "DiskBytesPersec: " & \$objItem.DiskBytesPersec & @CRLF
\$Output &= "DiskTransfersPersec: " & \$objItem.DiskTransfersPersec & @CRLF
\$Output &= "DiskWriteBytesPersec: " & \$objItem.DiskWriteBytesPersec & @CRLF
\$Output &= "DiskWritesPersec: " & \$objItem.DiskWritesPersec & @CRLF
\$Output &= "Frequency_Object: " & \$objItem.Frequency_Object & @CRLF
\$Output &= "Frequency_PerfTime: " & \$objItem.Frequency_PerfTime & @CRLF
\$Output &= "Frequency_Sys100NS: " & \$objItem.Frequency_Sys100NS & @CRLF
\$Output &= "Name: " & \$objItem.Name & @CRLF
\$Output &= "PercentDiskTime: " & \$objItem.PercentDiskTime & @CRLF
\$Output &= "PercentDiskTime_Base: " & \$objItem.PercentDiskTime_Base & @CRLF
\$Output &= "PercentDiskWriteTime: " & \$objItem.PercentDiskWriteTime & @CRLF
\$Output &= "PercentDiskWriteTime_Base: " & \$objItem.PercentDiskWriteTime_Base & @CRLF
\$Output &= "PercentIdleTime: " & \$objItem.PercentIdleTime & @CRLF
\$Output &= "PercentIdleTime_Base: " & \$objItem.PercentIdleTime_Base & @CRLF
\$Output &= "SplitIOPerSec: " & \$objItem.SplitIOPerSec & @CRLF
\$Output &= "Timestamp_Object: " & \$objItem.Timestamp_Object & @CRLF
\$Output &= "Timestamp_PerfTime: " & \$objItem.Timestamp_PerfTime & @CRLF
\$Output &= "Timestamp_Sys100NS: " & \$objItem.Timestamp_Sys100NS & @CRLF
if Msgbox(1,"WMI Output",\$Output) = 2 then ExitLoop
\$Output=""
Next
Else
Msgbox(0,"WMI Output","No WMI Objects Found for class: " & "Win32_PerfRawData_PerfDisk_PhysicalDisk" )
Endif

Then i found this in A1 scriptomatic, i must have missed it last night, mind you it was 2am

I havent deleteed any of the outputs yet so you can see the full list

Which out of these will be most usefull for what i need?

I just need an average speed of transfer for eg 100mb/s so which is the most suitable to give me that figure?

i will be doing something like this

if data is going through at 100mb/s and you have 5.37GB(5370mb) in theory it will take 53.7 seconds to transfer but we know hard drives rarely perform at a given speed so i just need a rough average speed to calculate against, yes i know this wont be very exact but its a rough figure.

and how do i tie it to just one drive ie:

\$target = "C:\"

Thanks for the links guys, i had a look at the C# code and i dont know anything about C# so thats out, and checked Ascend4nt code and geez cant even work out how to run it, to advanced for me

If Ive just helped you ... miracles do happen. Chimaera

##### Share on other sites

I missed Win32_PerfRawData_PerfDisk_PhysicalDisk in Scriptomatic Use this Function to get an idea in KB/MB/GB >>

Func _ByteSuffix(\$iBytes, \$iPlaces = 2)
Local \$A, \$aArray[6] = [" B", " KB", " MB", " GB", " TB", " PB"]
While \$iBytes > 1023
\$A += 1
\$iBytes /= 1024
WEnd
Return Round(\$iBytes, \$iPlaces) & \$aArray[\$A]
EndFunc   ;==>_ByteSuffix

Edited by guinness

##### Share on other sites

Ok that helps thanks m8

Now i just gotta find a way to target one drive only ie C:\

If Ive just helped you ... miracles do happen. Chimaera

##### Share on other sites

Yes per disk, but for me it opens and closes 4 times as i have 4 drives and if i use the logical version 6 times..

I need it to just show the targetted drive which makes it more directable with the rest of the code it will be with.

eg:

\$target = "C:\"

Chimaera

If Ive just helped you ... miracles do happen. Chimaera

##### Share on other sites

Update

Had to swop to Win32_PerfRawData_PerfDisk_LogicalDisk due to scores being added together when more than one partition existed

Done some benchmarking

I have 3 drives

Bootable (main drive) OCZ SSD @197 MB/s

Bootable Western Digital Raptor @ 69 MB/s

Storage drive Non BOOT @ 110.1 MB/s

The raptor is very old and suffers a performance hit when you boot the drive and test it = to 60.1 MB/s loss of 9 MB/s, but is quicker accesed from the SSD

I cannot get the code to reliably show any of these figures, whilst the drives are booted probably because and its a guess, because although the drive is active its not actually moving files in any quantity from drive to drive.

Is there a way to do a test packet of data and retrieve a transfer speed from that??, it would be much simpler.

Sort of like create a dummy file of 1mb and transfer it to the second drive then transfer it back and get speeds from the transfer?

Any thoughts?

Edited by Chimaera

If Ive just helped you ... miracles do happen. Chimaera

##### Share on other sites

I've added a little ' example to the PDH Performance Counters thread. That may or may not help you. Anytime someone uses WMI with 'Win32_PerfRawData', its a Performance Counter, and all of them should be able to be read through my PDH Performance Counters functions (which are alot faster than WMI).

##### Share on other sites

Thanks for you input Ascend4nt, nice piece of work..

Unfortunatly it wont give me the max possible transfer speed for the drive i need unless i abuse the drive in some way to make the Max Read/Write stats hit the max for a few seconds.

And heres me thinking this should be reasonably simple lol

Basically before i do a backup report i need a figure (time) that it will take to transfer the amount of data (backup) from their drive to my own.

And then those results will give me the overall time for that particular computer, as we know all hard drives vary enormously in speed so i decided that would be the best way to measure it.

I started measuring cpu and cores etc but the drive will always be the limitation.

Then once i know the fastest it can transfer say 1 MB of data then i can use maths to give me the total time to achieve the backup.

Maybe it needs some form of test to stress (gently) the drive like copying a 1mb chunk back and forth a few times to give the time to max the stats between the 2 drives

I always use \$source and \$target for the 2 drives as they are set from a Gui.

Then i suppose i would need a \$source_test and \$target_test variable so i can test them against each other and the lowest speed drive is the figure that i would use for the calculation.

Ps this is more like a pre backup check im trying to get working, no data will actually be copied its just a accurate check of, yes madam you have this much data and it will take this long to do the task...do you wish to proceed

If Ive just helped you ... miracles do happen. Chimaera

##### Share on other sites

My little example can be modified to test at shorter intervals (currently it tests every 1/2 second - you can test at 1/4 or less). I'd suggest you create dummy files of at least 1/2 GB, though the larger the better - and then copy it from/to the drive you want to test. Remember that Windows buffers information so you'll want to create a new dummy file for each test. The tests aren't going to be totally accurate, as different parts of the drive, and fragmentation, can cause differences in speed. You'd need a professional tool that works in different parts of the drive to get a more accurate average, however for simple 'roundabout' figures I don't see any harm to the above.

And btw, creating dummy files is pretty easy - you just need to create a file, set the file position to the size you want it (-1 byte), and write a single byte before closing it. (credits to trancexx for that quick and dirty method).

Edited by Ascend4nt

##### Share on other sites

Thanks for the info Ascend4nt

It dosent need to be dead accurate all i need to know is within a mb either way ish the max read and write of a drive that i point it to C,D etc, i will only need it to focus on just the drives i give it and achieve the figures for the calculation. if the calc is 5 minutes either way it wont matter, its only a projected guess at how long the backup would take to be done.

And btw, creating dummy files is pretty easy - you just need to create a file, set the file position to the size you want it (-1 byte), and write a single byte before closing it. (credits to trancexx for that quick and dirty method).

I have no idea what this means im still more or less a noob lol

If Ive just helped you ... miracles do happen. Chimaera

##### Share on other sites

For creating a dummy file, see trancexx's post in I suggested that assuming you had more than one hard drive though (doing backups..).

If you don't have more than one hard drive however, then I suppose you can create huge amounts of data in memory and write it to the disk (or read it from the disk into memory). I wouldn't know whether Windows buffering and file write-delay features would affect any of this... but even taking that out of the equation, you'll need to make sure you have a large enough amount of space available in memory to read from or write to the given file.

The 2+ hard drive scenario made more sense to me, but then I realized the individual drives would each have their own potential speed differences (didn't think that one through). You could make sure you are copying from (or copying to) the fastest hard drive (like a SSD) though..

##### Share on other sites

Another point is the drives i will be backing up are customer drives on old pcs, that will be slow and prob some close to dying. [and i will only be bacing up one drive at a time due to slow pcs etc]

they wont have SSD's lol, im a gamer thats why i have one but they are rare, ive prob only seen one at work other than mine.

Most normal people still come in to buy an 40 or 80GB drive which we dont even sell anymore, and most older laptops are small drives.

The finding the speed is for one reason only ...to give me a figure of how long an expected backup will take to do.

Thats what this is all for that one calculation..

Thats why i was messing with Win32_PerfRawData_PerfDisk_LogicalDisk because it dosent add drives together like the Win32_PerfRawData_PerfDisk_PhysicalDisk does when it has 2 partitions on one drive it gives a dual result which is no good for my needs.

I wish there was a simple way to do the speed but its not looking that way, im just hoping i end up with a function that gives me the figure but i think it will be beyond my talents to achieve it ..time will tell.

Chimaera

Edited by Chimaera

If Ive just helped you ... miracles do happen. Chimaera

##### Share on other sites

Thats why i was messing with Win32_PerfRawData_PerfDisk_LogicalDisk because it dosent add drives together like the Win32_PerfRawData_PerfDisk_PhysicalDisk does when it has 2 partitions on one drive it gives a dual result which is no good for my needs.

My example can easily be modified to show Logical Disk read/writes, but I think it's best to look at each hard drive as a whole. Otherwise, if another partition is being read/written to at the same time, you'll wind up with a bad representation. However, if you know beforehand that nothing is going to be read/written to the other partitions, then using Logical Disk is a much simpler way, especially if you don't know the hard drive each logical letter is mapped to.

##### Share on other sites

Hello

I understand that it might not be the right answer but I carry out hardware testing and I am working with small 2.5" HDD up to 1.5 TB in special shock mounts to protect products. I use test scripts looking at transfer rate ( SATA / USB2 & USB3) using commercial software for HDD benchmarking.

Why not adapt a program like this to use autit scripts to control the automation of a set of tests ....just an idea

I use Crystal Disk Mark and others but this is my thoughts on another approach without having to fully understand the different HDD tests and diagnostics for 2 & 3 Platter HDD running at different speed and track densities.

good luck

regards

John

##### Share on other sites

Thanks john ill look into it

im really not interested in all the wealth of info that is available on hard drives

because the transfer rate is the only factor for me, its a shame there isnt an easy solution, currently ive had to "guess" at a speed so i set a approx figure and work from there

all i need my script to do is flick the drive and/or maybe throw a test gig onto it and return the variable of \$transfer_speed

Other than that i shall have to wait until my coding reaches a level to be able to decipher Ascend4nt's code

Thanks to all who contributed

Chimaera

If Ive just helped you ... miracles do happen. Chimaera

##### Share on other sites

Thanks john ill look into it

im really not interested in all the wealth of info that is available on hard drives

because the transfer rate is the only factor for me, its a shame there isnt an easy solution, currently ive had to "guess" at a speed so i set a approx figure and work from there

all i need my script to do is flick the drive and/or maybe throw a test gig onto it and return the variable of \$transfer_speed

Other than that i shall have to wait until my coding reaches a level to be able to decipher Ascend4nt's code

Thanks to all who contributed

Chimaera

Disk Benchmark was the other tool I use

## Create an account

Register a new account

×

• Wiki

• Back

• Git