本文介绍了基于读/写速度和HDD缓冲区大小的HDD访问+搜索时间计算算法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想编写一个将通过执行基准来计算平均(访问+搜索)HDD时间的应用程序.我知道如何测试从HDD到内存的文件读取/写入速度,并且我可以在制造商页面上检查HDD的内部缓冲区大小.测试将在碎片整理分区上执行,因此我认为结果不是真实值的近似值.如果读取速度等于写入速度,那我可以做到

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.

推荐答案

首先,我将使用扇区访问而不是文件访问,以避免 FAT 和碎片影响基准.部门访问取决于平台.

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

但是您可以使用的任何文件访问例程都应该起作用,只需将文件名更改为"\\\\.\\A:"\\\\.\\PhysicalDrive0 .要访问软盘和 USB 等移除介质,请使用"\\\\.\\A:",但对于硬盘驱动器,请使用\\\\.\\PhysicalDrive0,因为第一种方法不适用于这些介质.还要将驱动器号A HDD 编号0更改为所需的值...

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...

在窗口 VCL C ++ 中,我这样做:

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);
        }
    }

它将首先打开作为设备的 HDD 驱动器(这就是文件名如此奇怪的原因).从编程方面,您可以假定它是包含 HDD 的所有扇区的文件.

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.

请注意,您不应覆盖文件系统!!! 因此,如果要写文件,请不要忘记恢复原始扇区.同样安全的是避免对第一个扇区(通常存储引导和 FAT 的第一扇区)进行写访问,因此,在发生错误或关机时,您不会丢失 FS .

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.

上面的代码读取 HDD0 的引导扇区(如果可访问)并将其保存到文件中.

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

如果您没有 VCL ,请使用 winapi C ++部门您可以使用的访问示例 OS API .

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

对于 HDD 缓冲区估计/测量,我将使用以下方法:

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

因为这是同一件事,而不是通过内存传输来进行光盘访问.

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

我将使用 winapi 中的QueryPerformanceCounter进行时间测量(应该绰绰有余).

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. 分别测量读写速度

transfer_read_rate = transfer_read_size / transfer_read_time
transfer_write_rate = transfer_write_size / transfer_write_time

  • 混合摊位费率(平均)

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

    其中(transfer_read_time + transfer_write_time)可以直接测量.

    当我将内存基准更改为HDD时(仅通过将STOSD传输替换为连续扇区读取),结果如下所示(用于矿山设置):

    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):

    您可以通过简单地测量随机位置的平均寻道时间和平均寻道时间来添加寻道时间测量...并且如果还添加HDD几何形状(每个磁道的扇区数),则可以更精确地测量速率,因为可以在磁道之间添加寻道时间等式...

    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 ...

    这篇关于基于读/写速度和HDD缓冲区大小的HDD访问+搜索时间计算算法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

  • 09-05 07:23
    查看更多