F
So, ich habe das Programm mal noch ein wenig aufgewertet (Protokollierung + Fehlerabfang).
Meine Ergebnisse nach dem Test der 4 Partitionen (C ist dass vollste LW (600 MB frei), I und J sind fast leer):
03.09.03 Laufwerk C: Schreiben: 21.9684 MB/s Lesen: 23.5868 MB/s
03.09.03 Laufwerk D: Schreiben: 31.6289 MB/s Lesen: 31.2728 MB/s
03.09.03 Laufwerk I: Schreiben: 46.0476 MB/s Lesen: 45.1739 MB/s
03.09.03 Laufwerk J: Schreiben: 44.1371 MB/s Lesen: 43.7382 MB/s
#include <windows.h>
#include <conio.h>
#include <iostream>
#include <fstream>
#include <ctime>
using namespace std;
typedef unsigned long ulong;
int main(void)
{
//Für den Schreib/Lesetest WINAPI verwenden, da fstream nur gepuffert arbeitet
HANDLE hFile;
char drive[] = "C";
char file[] = ":\\BENCH_TESTFILE.TMP";
char dir[256];
ulong bytesRead = 0,
bytesWritten = 0,
w_usedTime = 0,
r_usedTime = 0,
w_startTime = 0,
r_startTime = 0;
const int SIZE_TO_WRITE = 300 *1024 *1024; //Grösse der Testdatei in Byte
const int BUF_SIZE = 256 *1024; //Puffergrösse
char *readData = new char[BUF_SIZE];
char *writeData = new char[BUF_SIZE];
for(int j=0; j<BUF_SIZE; ++j)
writeData[j] = '0';
cout << "Dies ist ein simpler Festplatten-Geschwindigkeitstest." << endl;
cout << "Sie sollten mindestens " << SIZE_TO_WRITE/1024/1024 << " MB auf dem entspr. Laufwerk frei haben." << endl;
cout << "Welches Laufwerk wollen Sie testen? (nur den Laufwerksbuchstaben eingeben)" <<endl << endl;
cout << "Laufwerk: ";
cin >> drive;
if(drive[1] != '\0' || !((drive[0]>='a' && drive[0]<='z') || (drive[0]>='A' && drive[0]<='Z')) ){
cout << "Ungueltiges Laufwerk." << endl;
getch();
return 0;
}
//in Laufwerksbuchstaben in Grossbuchstaben konvertieren
if(drive[0]>='a' && drive[0]<='z')
drive[0] += ('A' - 'a');
strcpy(dir, drive);
strcat(dir, file);
hFile = CreateFile(dir,GENERIC_WRITE,FILE_SHARE_READ,NULL,CREATE_ALWAYS,FILE_ATTRIBUTE_NORMAL | FILE_FLAG_NO_BUFFERING,NULL);
if (hFile == INVALID_HANDLE_VALUE)
return 0;
cout << "Test wird gestartet:" << endl;
cout << "Erzeuge temporaere Datei " << dir << endl;
cout << "Schreibtest..." << flush;
w_startTime = GetTickCount();
for(ulong i=0; i<SIZE_TO_WRITE; i+=bytesWritten){
WriteFile(hFile, writeData, BUF_SIZE, &bytesWritten, NULL);
}
CloseHandle(hFile);
w_usedTime = (GetTickCount() - w_startTime);
cout << w_usedTime << " ms" << endl;
cout << "Lesetest..." <<flush;
hFile = CreateFile(dir,GENERIC_READ,FILE_SHARE_READ,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL | FILE_FLAG_NO_BUFFERING,NULL);
if (hFile == INVALID_HANDLE_VALUE)
return 0;
r_startTime = GetTickCount();
for(ulong k=0; k<SIZE_TO_WRITE; k+=bytesRead){
ReadFile(hFile, readData, BUF_SIZE, &bytesRead, NULL);
}
CloseHandle(hFile);
r_usedTime = (GetTickCount() - r_startTime);
cout << r_usedTime << " ms" << endl;
cout << "Loesche temporaere Datei " << dir << endl;
remove(dir);
delete[] readData;
delete[] writeData;
float w_transferrate = (SIZE_TO_WRITE/1024.0f/1024.0f)/(w_usedTime/1000.0f);
float r_transferrate = (SIZE_TO_WRITE/1024.0f/1024.0f)/(r_usedTime/1000.0f);
cout << "----------------------------------------------------------" << endl;
cout << "Ergebnis des Tests: " << endl << endl;
cout << "Tranferrate - schreiben: " << w_transferrate << " MB/s" << endl;
cout << "Tranferrate - lesen : " << r_transferrate << " MB/s" << endl;
//Protokollieren
time_t t = time(NULL);
tm *theTime = localtime(&t);
ofstream out("bench_results.txt", ios::app);
//Datum formatiert schreiben
out.width(2); out.fill('0'); out << theTime->tm_mday <<".";
out.width(2); out.fill('0'); out << theTime->tm_mon+1 << ".";
out.width(2); out.fill('0'); out << theTime->tm_year-100;
out << " Laufwerk " << drive << ": Schreiben: " << w_transferrate << " MB/s Lesen: " << r_transferrate << " MB/s" << endl;
out.close();
cout << "\nMoechten Sie mit die Ergebnisse mit vorherigen Tests vergleichen? (j/n) " << flush;
if(getch() == 'j'){
system("cls");
ifstream in("bench_results.txt");
if(!in)
return 0;
char line[256];
while(!in.eof()){
in.getline(line, 256);
cout << line << endl;
}
in.close();
getch();
}
return 0;
}