HDD access + search time calculation algorithm based on read/write speed and HDD buffer size

廉价感情. 提交于 2019-12-25 00:50:15

问题


I want to write application that will calculate average (access + search) HDD time by performing a benchmark. I know how to do test on file read/wite speed from HDD to memory and I can check on manufacturer page what is HDD's internal buffer size. Test would be performed on defragmentet partition so I think the result isn't bad approximation of real values. If read speed were equal to write speed then I could do

average_value = (copy_time - (file_size / read_speed * 2)) / (file_size / HDD_buffer_size * 2)

but read speed usually differs from write speed so this folrmula doesn't apply.

Please someone answer what the formula should be for that.


回答1:


First I would use sector access instead of file to avoid FAT and fragmentation influencing benchmark. Sector access is platform depended.

But any file access routine you got at your disposal should work just change the filename to "\\\\.\\A:" or \\\\.\\PhysicalDrive0. To access removal media like floppies and USB keys use "\\\\.\\A:" but for hard drives use \\\\.\\PhysicalDrive0 as the first method will not work for those. Also change the drive letter A or HDD number 0 to whatever you need...

In Window VCL C++ I do something like this:

int hnd;
BYTE dat[512];
hnd=FileOpen("\\\\.\\PhysicalDrive0",fmOpenRead);
if (hnd>=0)
    {
    FileSeek(hnd,0*512,0); // position to sector you want ...
    FileRead(hnd,dat,512); // read it
    FileClose(hnd);
    hnd=FileCreate("bootsector.dat");
    if (hnd>=0)
        {
        FileWrite(hnd,dat,512);
        FileClose(hnd);
        }
    }

It will open first HDD drive as device (that is why the file name is so weird). From programming side you can assume it is file containing all the sectors of your HDD.

Beware you should not overwrite file system !!! So if you are writing do not forget to restore original sectors. Also safer is to avoid write access for first sectors (where Boot and FAT usually is stored) so in case of a bug or shutdown you do not lose FS.

The code above reads boot sector of HDD0 (if accessible) and saves it to file.

In case you do not have VCL use winapi C++ sector access example or OS API you have at your disposal.

For the HDD buffers estimation/measurement I would use this:

  • Cache size estimation on your system?

As it is the same thing just instead of memory transfer do disc access.

I would use QueryPerformanceCounter from winapi for the time measurement (should be more than enough).

You are going a bit backwards with the equations I think (but might be wrong). I would:

  1. measure read and write speeds (separately)

    transfer_read_rate = transfer_read_size / transfer_read_time
    transfer_write_rate = transfer_write_size / transfer_write_time
    
  2. to mix booth rates (the average)

    transfer_avg_rate = (transfer_read_size + transfer_write_size) / (transfer_read_time + transfer_write_time)
    

    where (transfer_read_time + transfer_write_time) can be directly measured.

When I change my memory benchmark to HDD (just by replacing the STOSD transfer by continuous sector read The result looks like this (for mine setup):

You can add seek time measurement by simply measure and average seek time to random positions ... And if you also add HDD geometry (sectors per track) then you can more precisely measure the rates as you can add seek times between tracks to the equations ...




回答2:


Try this:

double read_time = file_size / read_speed ;
double write_time = file_size / write_speed ;

double total_time_if_no_delays = read_time + write_time ;
double avg_value = (copy_time - total_time_if_no_delays) / (file_size / HDD_buffer_size * 2) ;


来源:https://stackoverflow.com/questions/48445678/hdd-access-search-time-calculation-algorithm-based-on-read-write-speed-and-hdd

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!