Last active
          January 1, 2016 05:29 
        
      - 
      
 - 
        
Save vittorioromeo/8098965 to your computer and use it in GitHub Desktop.  
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | #include <list> | |
| #include <SSVUtils/SSVUtils.hpp> | |
| volatile bool state {false}; | |
| struct TestClass | |
| { | |
| volatile int k{0}; | |
| volatile int y{0}; | |
| volatile bool todel{false}; | |
| inline void doSomething() { state = !state; ++k; y+=k; } | |
| }; | |
| int main() | |
| { | |
| constexpr std::size_t count{1000000}; | |
| for(int i = 0; i < 3; ++i) | |
| { | |
| { | |
| std::vector<std::unique_ptr<TestClass>> container; | |
| ssvu::startBenchmark(); | |
| { | |
| container.reserve(count); | |
| for(auto i(0u); i < count; ++i) container.emplace_back(new TestClass); | |
| } | |
| ssvu::lo("VEC UPTR ADD") << ssvu::endBenchmark() << std::endl; | |
| ssvu::startBenchmark(); | |
| { | |
| for(auto& v : container) | |
| { | |
| v->doSomething(); | |
| v->todel = state; | |
| } | |
| } | |
| ssvu::lo("VEC UPTR ITR") << ssvu::endBenchmark() << std::endl; | |
| ssvu::startBenchmark(); | |
| { | |
| ssvu::eraseRemoveIf(container, [](const std::unique_ptr<TestClass>& mU){ return mU->todel; }); | |
| } | |
| ssvu::lo("VEC UPTR RM DEAD") << ssvu::endBenchmark() << std::endl; | |
| } | |
| { | |
| std::list<TestClass> container; | |
| ssvu::startBenchmark(); | |
| { | |
| for(auto i(0u); i < count; ++i) container.emplace_back(); | |
| } | |
| ssvu::lo("LIST ADD") << ssvu::endBenchmark() << std::endl; | |
| ssvu::startBenchmark(); | |
| { | |
| for(auto& v : container) | |
| { | |
| v.doSomething(); | |
| v.todel = state; | |
| } | |
| } | |
| ssvu::lo("LIST ITR") << ssvu::endBenchmark() << std::endl; | |
| ssvu::startBenchmark(); | |
| { | |
| ssvu::eraseRemoveIf(container, [](const TestClass& mU){ return mU.todel; }); | |
| } | |
| ssvu::lo("LIST DEAD") << ssvu::endBenchmark() << std::endl; | |
| } | |
| } | |
| return 0; | |
| } | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment