#include <iostream>
#include <fstream>
#include <time.h>
using namespace std;
int strToInt(string s)
{
int tmp = 0, i = 0;
bool m = false;
if(s[0] == '-') {
m = true;
i++;
}
for(; i < s.size(); i++)
tmp = 10 * tmp + s[i] - 48;
return m ? -tmp : tmp;
}
int main()
{
string size;
string choose;
double multiple = 0;
cout << "Podaj rozmiar pliku (liczba): ";
cin >> size;
cout << "Podaj jednostke (KB, MB, GB): ";
cin >> choose;
if (choose == "KB" or choose == "kb")
multiple = 1024;
else if (choose == "MB" or choose == "mb")
multiple = 1024 * 1024;
else if (choose == "GB" or choose == "gb")
multiple = 1024 * 1024 * 1024;
else
return 1;
int sizeout = strToInt(size) * multiple;
string filename = size;
filename += choose;
filename += ".lcf";
ofstream file;
file.open(filename.c_str(), ios::out);
double procent;
int count = 10;
int time = clock();
double donetime = 0;
cout << endl;
for (double i = 0; i < sizeout; i++)
{
procent = (i/sizeout)*100;
file << "A";
if (procent == count)
{
cout << procent << "% ";
count+=10;
}
}
file.close();
donetime = clock() - time;
double mbout = sizeout/(1024 * 1024);
double times = donetime / 1000;
double speedout = mbout/times;
cout << "Done!" << endl;
cout << "Zakonczono w: " << donetime << "ms.";
cout << "Srednia predkosc: " << speedout << " MB/s";
cin.get();
cin.get();
return 0;
}
Prędkość wg. programu to: 10.0414 przy 80MiB pliku.
Da się jakoś to przyspieszyć?