Advertisement
Guest User

Untitled

a guest
Apr 9th, 2020
184
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.36 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <string>
  4. #include <ctime>
  5.  
  6. using namespace std;
  7.  
  8. void Write()
  9. {
  10.     srand(time(0));
  11.     string str;
  12.     ofstream fout;
  13.     for (int i(0); i < 32000000; i++)
  14.     {
  15.         char a = rand() % 57 + 65;
  16.         str.push_back(a);
  17.     }
  18.     fout.open("C:\\Users\\Arclight\\Desktop\\Workplace C++\\Labs\\EVM\\laba3\\test.txt");
  19.     auto start = clock();
  20.     if (fout.is_open())
  21.         fout << str;
  22.     auto end = clock();
  23.     auto resWrite = difftime(end, start);
  24.     cout << "Time to write:" << resWrite / CLOCKS_PER_SEC << endl;
  25.     cout << "Write MB/s = " << 30.5 / (resWrite / CLOCKS_PER_SEC) << endl;
  26.     fout.close();
  27. }
  28. void Read()
  29. {
  30.     FILE* read;
  31.     fopen_s(&read, "C:\\Users\\Arclight\\Desktop\\Workplace C++\\Labs\\EVM\\laba3\\test.txt", "r");
  32.     long size;
  33.     size_t result;
  34.     size = 32000000;
  35.     char* buffer;
  36.     buffer = (char*)malloc(sizeof(char) * size);
  37.     auto start = clock();
  38.     result = fread(buffer, 1, size, read);
  39.     auto end = clock();
  40.     auto resRead = difftime(end, start);
  41.     cout << "Time to read:" << resRead / CLOCKS_PER_SEC << endl;
  42.     cout << "Read MB/s = " << 30.5 / (resRead / CLOCKS_PER_SEC) << endl;
  43.     cout << buffer[322];
  44.     fclose(read);
  45.     free(buffer);
  46. }
  47. int main()
  48. {
  49.     setlocale(LC_ALL, "Russian");
  50.     Write();
  51.     Read();
  52.     return 0;
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement