Advertisement
Guest User

Untitled

a guest
Mar 6th, 2019
166
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.95 KB | None | 0 0
  1. //=======================================================================
  2. // Copyright (c) 2014 Baptiste Wicht
  3. // Distributed under the terms of the MIT License.
  4. // (See accompanying file LICENSE or copy at
  5. // http://opensource.org/licenses/MIT)
  6. //=======================================================================
  7.  
  8. #include <random>
  9. #include <array>
  10. #include <vector>
  11. #include <list>
  12. #include <algorithm>
  13. #include <deque>
  14. #include <thread>
  15. #include <iostream>
  16. #include <cstdint>
  17. #include <typeinfo>
  18. #include <memory>
  19. #include <ctime>
  20.  
  21. struct SVisibilitySegment
  22. {
  23. bool m_Visible;
  24. size_t m_StartIndex;
  25. size_t m_EndIndex; // Inclusive
  26.  
  27. SVisibilitySegment(bool visible, size_t startIndex, size_t endIndex)
  28. : m_Visible(visible), m_StartIndex(startIndex), m_EndIndex(endIndex)
  29. {}
  30.  
  31. bool operator==(const SVisibilitySegment& other) const
  32. {
  33. return m_Visible == other.m_Visible && m_StartIndex == other.m_StartIndex && m_EndIndex == other.m_EndIndex;
  34. }
  35.  
  36. bool operator!=(const SVisibilitySegment& other) const
  37. {
  38. return !(*this == other);
  39. }
  40.  
  41. bool IsSinglePoint() const
  42. {
  43. return m_StartIndex == m_EndIndex;
  44. }
  45. };
  46.  
  47.  
  48. int main(){
  49. //Launch all the graphs
  50.  
  51. std::vector<SVisibilitySegment> segmentsVector;
  52. std::deque<SVisibilitySegment> segmentsDeque;
  53. int samples = 10000;
  54. std::clock_t begin = clock();
  55. for(int i = 0; i < samples ; ++i)
  56. {
  57. segmentsVector.push_back(SVisibilitySegment(true, 0, 1000 - 1));
  58. }
  59. std::clock_t end = clock();
  60. std::cout << "STD: Vector 'push_back' time:" << double(end - begin) / CLOCKS_PER_SEC << std::endl;
  61.  
  62. begin = clock();
  63. for(int i = 0; i < samples ; ++i)
  64. {
  65. segmentsDeque.push_back(SVisibilitySegment(true, 0, 1000 - 1));
  66. }
  67. end = clock();
  68. std::cout << "STD: Deque 'push_back' time: " << double(end - begin) / CLOCKS_PER_SEC << std::endl;
  69.  
  70.  
  71. begin = clock();
  72. for(int i = 0; i < samples ; ++i)
  73. {
  74. segmentsVector.emplace_back(SVisibilitySegment(true, 0, 1000 - 1));
  75. }
  76. end = clock();
  77. std::cout << "STD: Vector 'emplace_back' time: " << double(end - begin) / CLOCKS_PER_SEC << std::endl;
  78.  
  79. begin = clock();
  80. for(int i = 0; i < samples ; ++i)
  81. {
  82. segmentsDeque.emplace_back(SVisibilitySegment(true, 0, 1000 - 1));
  83. }
  84. end = clock();
  85. std::cout << "STD: Deque 'emplace_back' time: " << double(end - begin) / CLOCKS_PER_SEC << std::endl;
  86.  
  87. begin = clock();
  88. for(int i = samples; i > 0 ; --i)
  89. {
  90. segmentsVector.erase(std::prev(segmentsVector.end()));
  91. }
  92. end = clock();
  93. std::cout << "STD: Vector 'erase' time: " << double(end - begin) / CLOCKS_PER_SEC << std::endl;
  94.  
  95. begin = clock();
  96. for(int i = 0; i < samples ; ++i)
  97. {
  98. segmentsDeque.erase(segmentsDeque.begin() + 1);
  99. }
  100. end = clock();
  101. std::cout << "STD: Deque 'erase' time: " << double(end - begin) / CLOCKS_PER_SEC << std::endl;
  102.  
  103.  
  104. return 0;
  105. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement