※ 引述《a2a (尋找內心的平靜)》之銘言:
: 我不能編譯耶
: 貼上之後按compile 會出現
: 5 untitled1.cpp limits: No such file or directory
: 應該是指沒有第五行limits這個指令的用途吧
?
會嗎?
你的編譯器是?
有新版喔~~~
=============================
//#include "stdafx.h"
#include <iostream>
#include <fstream>
#include <time.h>
#include <limits>
#include <cstdio>
#include <fstream>
//#include <math.h>
using namespace std;
int main(void)
{
long double FileSize_inMB(const char*);
clock_t start = 0, finish = 0;
long double duration = 0;
unsigned int j = numeric_limits<unsigned int>::max();
//配置10MB的buffer,然後用於一次寫入10MB
//unsigned int Buffer_size = 1024*1024*10/sizeof(unsigned int);
unsigned int Buffer_size = 1024*1024*10;
unsigned int *pBuffer = new unsigned int[Buffer_size];
//unsigned int j = pow(2,(sizeof(j)*8))-1; //理論上啦,4294967295;
int MB_num = 0;
cout << "請輸入想測試的檔案大小(以10MB為單位):";
cin >> MB_num;
ofstream File_obj("TestData" , ios_base::out | ios_base::binary);
//製造出buffer區塊
for ( unsigned long Bi = 0; Bi < Buffer_size; ++Bi ){
pBuffer[Bi] = j;
}
//計時開始
start = clock();
for ( unsigned long i = 0; i < (MB_num/10); ++i )
File_obj.write( reinterpret_cast<char*>(pBuffer), Buffer_size);
//計時結束
finish = clock();
delete [] pBuffer;
duration = (long double)(finish - start) / CLOCKS_PER_SEC;
File_obj.close();
long double TestData_size = FileSize_inMB("TestData");
double Rate = TestData_size/duration;
cout << "測試時間:" << duration << "秒" << endl;
cout << "共寫入" << TestData_size << "MB" << endl;
cout << "磁碟寫入速率為" << Rate << "MB/秒" << endl << endl;
cin.ignore(256, '\n');
cout << "請按任一鍵繼續..." << std::endl;
cin.get();
remove("TestData");
return 0;
}
long double FileSize_inMB(const char* sFileName){
ifstream f;
f.open(sFileName, std::ios_base::binary | std::ios_base::in);
if (!f.good() || f.eof() || !f.is_open()) { return 0; }
f.seekg(0, std::ios_base::beg);
std::ifstream::pos_type begin_pos = f.tellg();
f.seekg(0, std::ios_base::end);
return (static_cast<long double>(f.tellg() - begin_pos))/(1024*1024);
}
=============================
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 221.169.236.105