diff --git a/src/autowiring/benchmark/AutoBench.cpp b/src/autowiring/benchmark/AutoBench.cpp index c000c90aa..fcff9122b 100644 --- a/src/autowiring/benchmark/AutoBench.cpp +++ b/src/autowiring/benchmark/AutoBench.cpp @@ -4,6 +4,7 @@ #include "ContextSearchBm.h" #include "ContextTrackingBm.h" #include "DispatchQueueBm.h" +#include "ObjectPoolBm.h" #include "PrintableDuration.h" #include "PriorityBoost.h" #include @@ -46,6 +47,7 @@ static std::map sc_commands = { MakeEntry("dispatch", "Dispatch queue execution rate", &DispatchQueueBm::Dispatch), MakeEntry("contextenum", "CoreContextEnumerator profiling", &ContextTrackingBm::ContextEnum), MakeEntry("contextmap", "ContextMap profiling", &ContextTrackingBm::ContextMap), + MakeEntry("objpool", "Object pool behaviors", &ObjectPoolBm::Allocation), }; static Benchmark All(void) { diff --git a/src/autowiring/benchmark/CMakeLists.txt b/src/autowiring/benchmark/CMakeLists.txt index 623a4f326..628ff00d9 100644 --- a/src/autowiring/benchmark/CMakeLists.txt +++ b/src/autowiring/benchmark/CMakeLists.txt @@ -9,6 +9,8 @@ set(AutoBench_SRCS DispatchQueueBm.h DispatchQueueBm.cpp Foo.h + ObjectPoolBm.h + ObjectPoolBm.cpp PriorityBoost.h PriorityBoost.cpp PrintableDuration.h diff --git a/src/autowiring/benchmark/ObjectPoolBm.cpp b/src/autowiring/benchmark/ObjectPoolBm.cpp new file mode 100644 index 000000000..f6a7a9890 --- /dev/null +++ b/src/autowiring/benchmark/ObjectPoolBm.cpp @@ -0,0 +1,65 @@ +// Copyright (C) 2012-2015 Leap Motion, Inc. All rights reserved. +#include "stdafx.h" +#include "ObjectPoolBm.h" +#include "Benchmark.h" +#include +#include +#include + +static const size_t n = 100; + +// Dummy struct of ten integers--needed because unique_ptr doesn't compile +struct tenPack { int dummy[10]; }; + +// Type that will perform a secondary allocation on construction +struct filling_vector { + filling_vector(void) { + other.resize(100); + } + + std::vector other; +}; + +template +void profile_basic(Stopwatch& sw) { + std::vector> mem; + + // Initial set of allocations: + for (size_t i = n; i--;) + mem.emplace_back(new T); + mem.clear(); + + // Now simulate something where an object pool might have been handy + for (size_t k = n; k--;) { + sw.Start(); + for (size_t i = n; i--;) + mem.emplace_back(new T); + sw.Stop(n * n); + mem.clear(); + } +} + +template +void profile_pool(Stopwatch& sw) { + ObjectPool pool; + pool.Preallocate(n); + + // Now simulate something where an object pool might have been handy + std::vector> mem; + for (size_t k = n; k--;) { + sw.Start(); + for (size_t i = n; i--;) + mem.emplace_back(pool()); + sw.Stop(n * n); + mem.clear(); + } +} + +Benchmark ObjectPoolBm::Allocation(void) { + return { + { "basic", &profile_basic }, + { "complex", &profile_basic }, + { "pool_basic", &profile_pool }, + { "pool_complex", &profile_pool } + }; +} diff --git a/src/autowiring/benchmark/ObjectPoolBm.h b/src/autowiring/benchmark/ObjectPoolBm.h new file mode 100644 index 000000000..318a2991f --- /dev/null +++ b/src/autowiring/benchmark/ObjectPoolBm.h @@ -0,0 +1,9 @@ +// Copyright (C) 2012-2015 Leap Motion, Inc. All rights reserved. +#pragma once + +struct Benchmark; + +class ObjectPoolBm { +public: + static Benchmark Allocation(void); +}; \ No newline at end of file