SHARE
TWEET

Untitled

a guest Sep 16th, 2019 88 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include <ctime>
  3. #include <cstdio>
  4. #include <windows.h>
  5.  
  6. COORD pos;
  7. HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
  8.  
  9. void SP (short x, short y)
  10. {
  11.     pos.X = x;
  12.     pos.Y = y;
  13.     SetConsoleCursorPosition(hConsole, pos);
  14. }
  15.  
  16. int pow (int a, int b)
  17. {
  18.     int ans = 1;
  19.     for (int i = 0; i < b; ++i){
  20.         ans *= a;
  21.     }
  22.     return ans;
  23. }
  24.  
  25. void read_lab(bool scan)
  26. {
  27.     char path[8] = "1EX.txt";
  28.     for (short i = 4; i <= 7; ++i){
  29.         clock_t start = clock();
  30.         path[2] = char ('0' + i);
  31.         freopen(path, "r", stdin);
  32.         double input;
  33.         for (int c = 0; c < pow(10, i); ++c){
  34.             if (scan) scanf("%f", &input);
  35.             else std :: cin >> input;
  36.         }
  37.         double time = (clock() - start) / (double) CLOCKS_PER_SEC;
  38.         if (scan) SP(5, i - 3);
  39.         else SP(30, i - 3);
  40.         printf("%.3f", time);
  41.     }
  42. }
  43.  
  44. void design_bold()
  45. {
  46.     std::cout << '\n' << "1E4\n" << "1E5\n" << "1E6\n" << "1E7\n";
  47. }
  48.  
  49. void solve()
  50. {
  51.     design_bold();
  52.  
  53.     SP(5, 0);
  54.     std :: cout << "Time for scanf(sec):";
  55.     read_lab(true);
  56.  
  57.     SP(30, 0);
  58.     std :: cout << "Time for cin(sec):";
  59.     read_lab(false);
  60. }
  61.  
  62. int main()
  63. {
  64.     try {
  65.         solve();
  66.     } catch (...) {
  67.         return 1;
  68.     }
  69.     return 0;
  70. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top