fork download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <iterator>
  4. #include <x86intrin.h>
  5.  
  6.  
  7. constexpr unsigned NN=1024*1024*4;
  8. #define time
  9. #ifdef time
  10. #define print(a...) ;
  11. #else
  12. #define print(a...) printf(a)
  13. #endif
  14. size_t st;
  15. struct A {
  16. char* arr;
  17. A() noexcept {
  18. print("+A() [%+03lld]\n",(size_t)this-st);
  19. arr=new char[NN];
  20. for (int i=0;i<NN;i++)
  21. arr[i]=i;
  22. }
  23. ~A() noexcept {
  24. print("~A() [%+03lld]\n",(size_t)this-st);
  25. if (arr)
  26. delete[] arr;
  27. arr=nullptr;
  28. }
  29. void operator=(A&& r)noexcept {
  30. print("=A(&&) [%+03lld] = [%+03lld]\n",(size_t)this-st,(size_t)&r-st);
  31. if (arr)
  32. delete[] arr;
  33. arr=r.arr;
  34. r.arr=nullptr;
  35. }
  36. void operator=(A& r)noexcept {
  37. print("=A(&) [%+03lld] = [%+03lld]\n",(size_t)this-st,(size_t)&r-st);
  38. if (arr)
  39. delete[] arr;
  40. arr=new char[NN];
  41. for (int i=0;i<NN;i++)
  42. arr[i]=r.arr[i];
  43. }
  44. A(A&& r)noexcept {
  45. print("+A(&&) [%+03lld] ([%+03lld])\n",(size_t)this-st,(size_t)&r-st);
  46. arr=r.arr;
  47. r.arr=nullptr;
  48. }
  49. A(A& r)noexcept {
  50. print("+A(&) [%+03lld] ([%+03lld])\n",(size_t)this-st,(size_t)&r-st);
  51. arr=new char[NN];
  52. for (int i=0;i<NN;i++)
  53. arr[i]=r.arr[i];
  54.  
  55. }
  56. A operator+(A& r)noexcept {
  57. A temp;
  58. for (int i=0;i<NN;i++)
  59. temp.arr[i]=arr[i]+r.arr[i];
  60. print(" +(&) [%+03lld] = [%+03lld]+[%+03lld]\n",(size_t)&temp-st,(size_t)this-st,(size_t)&r-st);
  61. return temp;
  62. }
  63. void operator+=(A& r)noexcept {
  64. for (int i=0;i<NN;i++)
  65. arr[i]+=r.arr[i];
  66. print(" +=(&) [%+03lld] += [%+03lld]\n",(size_t)this-st,(size_t)&r-st);
  67. }
  68. };
  69.  
  70. void add(A& a,A& b,A& c)noexcept {
  71. print("f+(&) [%+03lld] = [%+03lld]+[%+03lld]\n",(size_t)&a-st,(size_t)&b-st,(size_t)&c-st);
  72. for (int i=0;i<NN;i++)
  73. a.arr[i]=b.arr[i]+c.arr[i];
  74. }
  75.  
  76. int main(void) noexcept{
  77. int r;st=(size_t)&r;
  78. size_t t1,t2;
  79. for (int u=0;u<3;u++){
  80. printf("\n ==1==\n");
  81. t1=_rdtsc();
  82. {
  83. A a,b,c;
  84. a=b+c;
  85. }
  86. t2=_rdtsc();
  87. printf(" %.1f\n",(t2-t1)*1.0e-6);
  88. printf("\n ==2==\n");
  89. t1=_rdtsc();
  90. {
  91. A a,b,c;
  92. add(a,b,c);
  93. }
  94. t2=_rdtsc();
  95. printf(" %.1f\n",(t2-t1)*1.0e-6);
  96. printf("\n ==3==\n");
  97. t1=_rdtsc();
  98. {
  99. A a,b,c;
  100. a=b;a+=c;
  101. }
  102. t2=_rdtsc();
  103. printf(" %.1f\n",(t2-t1)*1.0e-6);
  104. }
  105. system("pause");
  106. return 0;
  107. }
  108.  
Success #stdin #stdout #stderr 0.12s 19252KB
stdin
Standard input is empty
stdout
    ==1==
   63.1

    ==2==
   56.6

    ==3==
   48.0

    ==1==
   54.0

    ==2==
   48.8

    ==3==
   37.6

    ==1==
   37.2

    ==2==
   35.4

    ==3==
   37.3
stderr
sh: 1: pause: not found