Advertisement
Guest User

Untitled

a guest
Feb 15th, 2022
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.83 KB | None | 0 0
  1. unique_ptr+.c++
  2. --cut--
  3. #include <iostream>
  4. #include <memory> // для std::unique_ptr
  5.  
  6. #include "Item.h"
  7.  
  8. int main()
  9. {
  10. for (int i = 0; i < 100000000; ) {
  11. std::unique_ptr<Item> item(new Item(i));
  12. i++;
  13. }
  14.  
  15. return 0;
  16. }
  17. --cut--
  18. ================================================================================
  19. unique_ptr-.c++
  20. --cut--
  21. #include <iostream>
  22. #include <memory> // для std::unique_ptr
  23.  
  24. #include "Item.h"
  25.  
  26. int main()
  27. {
  28. for (int i = 0; i < 100000000; ) {
  29. Item* item = new Item(i);
  30. i++;
  31. delete item;
  32. }
  33.  
  34. return 0;
  35. }
  36. --cut--
  37. ================================================================================
  38. Item.h
  39. --cut--
  40. #include <unistd.h>
  41.  
  42. class Item
  43. {
  44. public:
  45. Item(int i):i(i)
  46. { write(STDOUT_FILENO, ">", 1); }
  47. ~Item()
  48. { write(STDOUT_FILENO, "<", 1); i--; }
  49. private:
  50. int i;
  51. };
  52. --cut--
  53. ================================================================================
  54. Makefile
  55. --cut--
  56. all: unique_ptr+ unique_ptr-
  57.  
  58. unique_ptr+: unique_ptr+.c++
  59. c++ $^ -o $@ -O3
  60.  
  61. unique_ptr-: unique_ptr-.c++
  62. c++ $^ -o $@ -O3
  63. --cut--
  64. ================================================================================
  65. ================================================================================
  66. ================================================================================
  67. два запуска "+"
  68. $ sudo perf stat ./unique_ptr+ >/dev/null
  69.  
  70. Performance counter stats for './unique_ptr+':
  71.  
  72. 17 986,22 msec task-clock # 1,000 CPUs utilized
  73. 60 context-switches # 0,003 K/sec
  74. 0 cpu-migrations # 0,000 K/sec
  75. 122 page-faults # 0,007 K/sec
  76. 63 842 579 962 cycles # 3,550 GHz
  77. 133 523 204 873 instructions # 2,09 insn per cycle
  78. 26 203 958 590 branches # 1456,891 M/sec
  79. 72 456 branch-misses # 0,00% of all branches
  80.  
  81. 17,987337609 seconds time elapsed
  82.  
  83. 5,579484000 seconds user
  84. 12,406853000 seconds sys
  85.  
  86.  
  87. $ sudo perf stat ./unique_ptr+ >/dev/null
  88. Performance counter stats for './unique_ptr+':
  89.  
  90. 17 917,53 msec task-clock # 1,000 CPUs utilized
  91. 124 context-switches # 0,007 K/sec
  92. 2 cpu-migrations # 0,000 K/sec
  93. 122 page-faults # 0,007 K/sec
  94. 63 179 246 976 cycles # 3,526 GHz
  95. 133 524 156 215 instructions # 2,11 insn per cycle
  96. 26 204 153 897 branches # 1462,487 M/sec
  97. 86 269 branch-misses # 0,00% of all branches
  98.  
  99. 17,920061593 seconds time elapsed
  100.  
  101. 5,931150000 seconds user
  102. 11,986282000 seconds sys
  103.  
  104.  
  105. ================================================================================
  106. ================================================================================
  107. ================================================================================
  108. два запуска "-"
  109. $ sudo perf stat ./unique_ptr- >/dev/null
  110. Performance counter stats for './unique_ptr-':
  111.  
  112. 17 844,46 msec task-clock # 1,000 CPUs utilized
  113. 50 context-switches # 0,003 K/sec
  114. 0 cpu-migrations # 0,000 K/sec
  115. 123 page-faults # 0,007 K/sec
  116. 63 310 787 822 cycles # 3,548 GHz
  117. 133 523 339 391 instructions # 2,11 insn per cycle
  118. 26 203 981 684 branches # 1468,466 M/sec
  119. 74 410 branch-misses # 0,00% of all branches
  120.  
  121. 17,845494383 seconds time elapsed
  122.  
  123. 5,940188000 seconds user
  124. 11,904377000 seconds sys
  125.  
  126.  
  127. $ sudo perf stat ./unique_ptr- >/dev/null
  128. Performance counter stats for './unique_ptr-':
  129.  
  130. 18 921,22 msec task-clock # 1,000 CPUs utilized
  131. 57 context-switches # 0,003 K/sec
  132. 1 cpu-migrations # 0,000 K/sec
  133. 123 page-faults # 0,007 K/sec
  134. 65 560 699 792 cycles # 3,465 GHz
  135. 133 528 879 861 instructions # 2,04 insn per cycle
  136. 26 204 948 357 branches # 1384,950 M/sec
  137. 151 713 branch-misses # 0,00% of all branches
  138.  
  139. 18,922880390 seconds time elapsed
  140.  
  141. 6,348399000 seconds user
  142. 12,572791000 seconds sys
  143.  
  144. ================================================================================
  145. все.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement