Skip to content

Instantly share code, notes, and snippets.

@vittorioromeo
Last active January 1, 2016 05:29
Show Gist options
  • Save vittorioromeo/8098965 to your computer and use it in GitHub Desktop.
Save vittorioromeo/8098965 to your computer and use it in GitHub Desktop.
#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