fork download
  1. #include <iostream>
  2. #include <chrono>
  3. #include <cstdlib>
  4. #include <cstddef>
  5.  
  6. typedef std::chrono::high_resolution_clock hres_clk;
  7. typedef std::chrono::nanoseconds ns;
  8.  
  9. #define MIN_BLOCK_SIZE 3276
  10. #define MAX_BLOCK_SIZE_L1 (32 * 1024 * 2)
  11. #define STEP 3276
  12.  
  13. int main() {
  14. uint8_t *p = (uint8_t*)malloc(MAX_BLOCK_SIZE_L1);
  15. for (size_t b = MIN_BLOCK_SIZE, i = 0; b <= MAX_BLOCK_SIZE_L1; b += STEP, i += 1) {
  16. auto pre = hres_clk::now();
  17. for (size_t c = 0; c < b; c += 1) {
  18. p[c] = c;
  19. }
  20. auto post = hres_clk::now();
  21. std::cout << i << '\t' << std::chrono::duration_cast<ns>(post - pre).count()
  22. << '\t' << b << '\t'
  23. << (std::chrono::duration_cast<ns>(post - pre).count() / (double) b) << '\n';
  24. }
  25. return 0;
  26. }
Success #stdin #stdout 0s 3092KB
stdin
Standard input is empty
stdout
0	3000	3276	0.915751
1	8000	6552	1.221
2	10000	9828	1.0175
3	13000	13104	0.992063
4	16000	16380	0.976801
5	17000	19656	0.864876
6	22000	22932	0.959358
7	26000	26208	0.992063
8	27000	29484	0.915751
9	29000	32760	0.885226
10	33000	36036	0.915751
11	36000	39312	0.915751
12	39000	42588	0.915751
13	42000	45864	0.915751
14	43000	49140	0.875051
15	47000	52416	0.896673
16	51000	55692	0.915751
17	53000	58968	0.898793
18	56000	62244	0.899685
19	57000	65520	0.869963