测试技术培训:如何测试磁盘写的速度 2

//测试写磁盘速度

void writeFileTestFun()

{

    //堆内存申请,显然栈内存不合适

    char* szTenMBBuf = (char*)malloc(WRITE_BUFF_SIZE); 

    (void)initBuf(szTenMBBuf, WRITE_BUFF_SIZE);

 

    size_t nBeginTicks = GetTickCount();

    cout << "BeginTime = " << nBeginTicks << endl;

 

    (void)writeFileFun(szTenMBBuf);

 

    size_t nEndTicks = GetTickCount();

    cout << "EndTime = " << nEndTicks << endl;

 

    size_t nSpan = nEndTicks - nBeginTicks;

    cout << "nSpanTime = " << nSpan << "ms" << endl; //ms

 

    float nTotalBytes = WRITE_BUFF_SIZE*MAX_WRITE_CNT;  //总写入字节数

    float nTotalTimes = (float)(nSpan) / 1000.0f;       //总耗费时间,单位s

 

    cout << "nTotalWriteBytes = " << nTotalBytes << endl;

    cout << "nTotalTimes = " << nTotalTimes << endl;

 

    float fSpeed =  nTotalBytes / nTotalTimes;

 

    cout << "Speed = " << fSpeed << "Byte/s" << endl;   //写入速度 Byte/s

    cout << "Speed = " << fSpeed / 1024.0f / 1024.0f << "MB/s" << endl; //写入速度 MByte/s

 

    if (NULL != szTenMBBuf)

    {

        free(szTenMBBuf);

        szTenMBBuf = NULL;

    }

}

int _tmain(int argc, _TCHAR* argv[])

{

    (void)writeFileTestFun();

    return 0;

}


你可能感兴趣的:(软件测试开发)