Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <string>
- #include <ctime>
- using namespace std;
- void Write()
- {
- srand(time(0));
- string str;
- ofstream fout;
- for (int i(0); i < 32000000; i++)
- {
- char a = rand() % 57 + 65;
- str.push_back(a);
- }
- fout.open("C:\\Users\\Arclight\\Desktop\\Workplace C++\\Labs\\EVM\\laba3\\test.txt");
- auto start = clock();
- if (fout.is_open())
- fout << str;
- auto end = clock();
- auto resWrite = difftime(end, start);
- cout << "Time to write:" << resWrite / CLOCKS_PER_SEC << endl;
- cout << "Write MB/s = " << 30.5 / (resWrite / CLOCKS_PER_SEC) << endl;
- fout.close();
- }
- void Read()
- {
- FILE* read;
- fopen_s(&read, "C:\\Users\\Arclight\\Desktop\\Workplace C++\\Labs\\EVM\\laba3\\test.txt", "r");
- long size;
- size_t result;
- size = 32000000;
- char* buffer;
- buffer = (char*)malloc(sizeof(char) * size);
- auto start = clock();
- result = fread(buffer, 1, size, read);
- auto end = clock();
- auto resRead = difftime(end, start);
- cout << "Time to read:" << resRead / CLOCKS_PER_SEC << endl;
- cout << "Read MB/s = " << 30.5 / (resRead / CLOCKS_PER_SEC) << endl;
- cout << buffer[322];
- fclose(read);
- free(buffer);
- }
- int main()
- {
- setlocale(LC_ALL, "Russian");
- Write();
- Read();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement