//測試寫磁盤速度
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();