fork download
  1. #include<bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. using ldbl = long double;
  6. using ll = long long;
  7.  
  8. const ldbl delta = 1e-9; const int N = 10; ll m[N], n[N], t[N];
  9.  
  10. namespace timer
  11. {
  12. typedef chrono::high_resolution_clock Clock_t;
  13. typedef chrono::time_point<Clock_t> Time_t;
  14. typedef chrono::microseconds Time_scale_t;
  15.  
  16. static Time_t present;
  17.  
  18. inline void reset()
  19. {
  20. present = Clock_t::now();
  21. }
  22.  
  23. inline ll elapsed_time()
  24. {
  25. auto past = present; reset();
  26.  
  27. return chrono::duration_cast<Time_scale_t>(present-past).count();
  28. }
  29. }
  30.  
  31. int main()
  32. {
  33. ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
  34.  
  35. n[0] = 1, timer::reset();
  36.  
  37. for(int j = 0; j < N; j++, n[j] = n[j-1]*10)
  38. {
  39. for(ldbl i_max = 1/ldbl(n[j]), i = 0; i <= i_max; i += delta)
  40. m[j]++;
  41.  
  42. t[j] = timer::elapsed_time();
  43. }
  44.  
  45. for(int j = 0; j < N; j++)
  46. cout << j << ": n = " << n[j] << ", ",
  47. cout << m[j] << " iteration(s), total loop execution-time = " << t[j] << " usec" << endl;
  48. }
Success #stdin #stdout 1.15s 15240KB
stdin
Standard input is empty
stdout
0: n = 1, 1000000000 iteration(s), total loop execution-time = 1039169 usec
1: n = 10, 100000000 iteration(s), total loop execution-time = 104531 usec
2: n = 100, 10000001 iteration(s), total loop execution-time = 10602 usec
3: n = 1000, 1000000 iteration(s), total loop execution-time = 1053 usec
4: n = 10000, 100000 iteration(s), total loop execution-time = 107 usec
5: n = 100000, 10001 iteration(s), total loop execution-time = 10 usec
6: n = 1000000, 1000 iteration(s), total loop execution-time = 1 usec
7: n = 10000000, 100 iteration(s), total loop execution-time = 0 usec
8: n = 100000000, 10 iteration(s), total loop execution-time = 0 usec
9: n = 1000000000, 1 iteration(s), total loop execution-time = 0 usec