Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //=======================================================================
- // Copyright (c) 2014 Baptiste Wicht
- // Distributed under the terms of the MIT License.
- // (See accompanying file LICENSE or copy at
- // http://opensource.org/licenses/MIT)
- //=======================================================================
- #include <random>
- #include <array>
- #include <vector>
- #include <list>
- #include <algorithm>
- #include <deque>
- #include <thread>
- #include <iostream>
- #include <cstdint>
- #include <typeinfo>
- #include <memory>
- #include <ctime>
- struct SVisibilitySegment
- {
- bool m_Visible;
- size_t m_StartIndex;
- size_t m_EndIndex; // Inclusive
- SVisibilitySegment(bool visible, size_t startIndex, size_t endIndex)
- : m_Visible(visible), m_StartIndex(startIndex), m_EndIndex(endIndex)
- {}
- bool operator==(const SVisibilitySegment& other) const
- {
- return m_Visible == other.m_Visible && m_StartIndex == other.m_StartIndex && m_EndIndex == other.m_EndIndex;
- }
- bool operator!=(const SVisibilitySegment& other) const
- {
- return !(*this == other);
- }
- bool IsSinglePoint() const
- {
- return m_StartIndex == m_EndIndex;
- }
- };
- int main(){
- //Launch all the graphs
- std::vector<SVisibilitySegment> segmentsVector;
- std::deque<SVisibilitySegment> segmentsDeque;
- int samples = 10000;
- std::clock_t begin = clock();
- for(int i = 0; i < samples ; ++i)
- {
- segmentsVector.push_back(SVisibilitySegment(true, 0, 1000 - 1));
- }
- std::clock_t end = clock();
- std::cout << "STD: Vector 'push_back' time:" << double(end - begin) / CLOCKS_PER_SEC << std::endl;
- begin = clock();
- for(int i = 0; i < samples ; ++i)
- {
- segmentsDeque.push_back(SVisibilitySegment(true, 0, 1000 - 1));
- }
- end = clock();
- std::cout << "STD: Deque 'push_back' time: " << double(end - begin) / CLOCKS_PER_SEC << std::endl;
- begin = clock();
- for(int i = 0; i < samples ; ++i)
- {
- segmentsVector.emplace_back(SVisibilitySegment(true, 0, 1000 - 1));
- }
- end = clock();
- std::cout << "STD: Vector 'emplace_back' time: " << double(end - begin) / CLOCKS_PER_SEC << std::endl;
- begin = clock();
- for(int i = 0; i < samples ; ++i)
- {
- segmentsDeque.emplace_back(SVisibilitySegment(true, 0, 1000 - 1));
- }
- end = clock();
- std::cout << "STD: Deque 'emplace_back' time: " << double(end - begin) / CLOCKS_PER_SEC << std::endl;
- begin = clock();
- for(int i = samples; i > 0 ; --i)
- {
- segmentsVector.erase(std::prev(segmentsVector.end()));
- }
- end = clock();
- std::cout << "STD: Vector 'erase' time: " << double(end - begin) / CLOCKS_PER_SEC << std::endl;
- begin = clock();
- for(int i = 0; i < samples ; ++i)
- {
- segmentsDeque.erase(segmentsDeque.begin() + 1);
- }
- end = clock();
- std::cout << "STD: Deque 'erase' time: " << double(end - begin) / CLOCKS_PER_SEC << std::endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement