fork(3) download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. struct timeit {
  5. decltype(chrono::high_resolution_clock::now()) begin;
  6. const string label;
  7. timeit(string label = "???") : label(label) { begin = chrono::high_resolution_clock::now(); }
  8. ~timeit() {
  9. auto end = chrono::high_resolution_clock::now();
  10. auto duration = chrono::duration_cast<chrono::milliseconds>(end - begin).count();
  11. cerr << duration << "ms elapsed [" << label << "]" << endl;
  12. }
  13. };
  14. const int MAXN = 1e5;
  15. const int NUMITERS = 10000;
  16. int A[MAXN];
  17. int main() {
  18. {
  19. timeit x("fused");
  20. for (int j = 1; j < NUMITERS; j++) {
  21. for (int i = 0; i < MAXN; i++) {
  22. A[i] += j;
  23. A[i] *= j;
  24. }
  25. }
  26. }
  27. {
  28. timeit x("unfused");
  29. for (int j = 1; j < NUMITERS; j++) {
  30. for (int i = 0; i < MAXN; i++)
  31. A[i] += j;
  32. for (int i = 0; i < MAXN; i++)
  33. A[i] *= j;
  34. }
  35. }
  36.  
  37. }
  38.  
Success #stdin #stdout #stderr 1.51s 4508KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
539ms elapsed [fused]
972ms elapsed [unfused]