Test technical training: How to test disk write Speed 2

Source: Internet
Author: User

5. The program is implemented as follows (very simple, no longer explained):

WriteFileDemo.cpp: Defines the entry point of the console application.

//

#include "stdafx.h"

#include <iostream>

#include <fstream>

using namespace Std;

#include <windows.h>

#include <WinBase.h>

#include <ctime>

Target Write file

Const char* G_psoutfile = "D:\\test_file\\1.txt";

Buffer size for one write

Const long write_buff_size = 10*1024*1024; 300MB bytes

Number of writes

#define MAX_WRITE_CNT 5

Buffer each byte is initialized to the ' a ' character

void Initbuf (char* pszbuf, int icnt)

{

for (int i = 0; i < icnt; ++i)

{

Pszbuf[i] = 97;

}

}

Loop Write file

void Writefilefun (char* szbuf)

{

Ofstream ofout (G_psoutfile);

int i = 0;

while (I < max_write_cnt)

{

Ofout << szbuf << Endl;

++i;

}

}

Test Write disk speed

void Writefiletestfun ()

{

Heap memory request, obviously stack memory inappropriate

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; Total number of bytes written

float ntotaltimes = (float) (nspan)/1000.0f; Total time spent, unit s

cout << "ntotalwritebytes =" << ntotalbytes << Endl;

cout << "ntotaltimes =" << ntotaltimes << Endl;

float fspeed = ntotalbytes/ntotaltimes;

cout << "Speed =" << fspeed << "byte/s" << Endl; Write Speed byte/s

cout << "Speed =" << fspeed/1024.0f/1024.0f << "MB/S" << Endl; Write Speed mbyte/s

if (NULL! = sztenmbbuf)

{

Free (SZTENMBBUF);

Sztenmbbuf = NULL;

}

}

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

{

(void) writefiletestfun ();

return 0;

}

Test technical training: How to test disk write Speed 2

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.