24 #include <type_traits> 56 template <
typename MakeFunction>
57 void runSmallInvokeBenchmark(std::size_t iters, MakeFunction make) {
58 auto lambda = [](
auto&
i) {
62 auto func = make(lambda);
65 for (
auto i = std::size_t{iters}; --
i;) {
70 template <
typename MakeFunction>
71 void runSmallCreateAndInvokeBenchmark(std::size_t iters, MakeFunction make) {
72 auto lambda = [](
auto&
i) {
77 for (
auto i = std::size_t{iters}; --
i;) {
78 auto func = make(lambda);
84 template <
typename MakeFunction>
85 void runBigAndInvokeBenchmark(std::size_t iters, MakeFunction make) {
86 auto suspender = BenchmarkSuspender{};
87 auto array = std::array<std::uint8_t, 4096>{};
89 auto lambda = [=](
auto&
i) {
95 auto func = make(lambda);
98 suspender.dismissing([&] {
99 for (
auto i = std::size_t{iters}; --
i;) {
105 template <
typename MakeFunction>
106 void runBigCreateAndInvokeBenchmark(std::size_t iters, MakeFunction make) {
107 auto suspender = BenchmarkSuspender{};
108 auto array = std::array<std::uint8_t, 1024>{};
111 auto lambda = [=](
auto&
i) {
117 suspender.dismissing([&] {
118 for (
auto i = std::size_t{iters}; --
i;) {
119 auto func = make(lambda);
128 using FPtr = size_t (*)(
size_t&);
129 runSmallInvokeBenchmark(iters, [](
auto&
f) {
return FPtr{
f}; });
132 runSmallInvokeBenchmark(
133 iters, [](
auto&
f) {
return std::function<size_t(size_t&)>{
f}; });
135 BENCHMARK(SmallFunctionStdFunctionWithReferenceWrapperInvoke, iters) {
136 runSmallInvokeBenchmark(iters, [](
auto&
f) {
137 return std::function<size_t(size_t&)>{std::ref(
f)};
141 runSmallInvokeBenchmark(
145 runSmallInvokeBenchmark(
150 BENCHMARK(SmallFunctionFunctionPointerCreateInvoke, iters) {
151 using FPtr = size_t (*)(
size_t&);
152 runSmallCreateAndInvokeBenchmark(iters, [](
auto&
f) {
return FPtr{
f}; });
154 BENCHMARK(SmallFunctionStdFunctionCreateInvoke, iters) {
155 runSmallCreateAndInvokeBenchmark(
156 iters, [](
auto&
f) {
return std::function<size_t(size_t&)>{
f}; });
158 BENCHMARK(SmallFunctionStdFunctionReferenceWrapperCreateInvoke, iters) {
159 runSmallCreateAndInvokeBenchmark(iters, [](
auto&
f) {
160 return std::function<size_t(size_t&)>{std::ref(
f)};
163 BENCHMARK(SmallFunctionFollyFunctionCreateInvoke, iters) {
164 runSmallCreateAndInvokeBenchmark(
167 BENCHMARK(SmallFunctionFollyFunctionRefCreateInvoke, iters) {
168 runSmallCreateAndInvokeBenchmark(
174 runBigAndInvokeBenchmark(
175 iters, [](
auto&
f) {
return std::function<size_t(size_t&)>{
f}; });
177 BENCHMARK(BigFunctionStdFunctionReferenceWrapperInvoke, iters) {
178 runBigAndInvokeBenchmark(iters, [](
auto&
f) {
179 return std::function<size_t(size_t&)>{std::ref(
f)};
183 runBigAndInvokeBenchmark(
187 runBigAndInvokeBenchmark(
193 runBigCreateAndInvokeBenchmark(
194 iters, [](
auto&
f) {
return std::function<size_t(size_t&)>{
f}; });
196 BENCHMARK(BigFunctionStdFunctionReferenceWrapperCreateInvoke, iters) {
197 runBigCreateAndInvokeBenchmark(iters, [](
auto&
f) {
198 return std::function<size_t(size_t&)>{std::ref(
f)};
201 BENCHMARK(BigFunctionFollyFunctionCreateInvoke, iters) {
202 runBigCreateAndInvokeBenchmark(
205 BENCHMARK(BigFunctionFollyFunctionRefCreateInvoke, iters) {
206 runBigCreateAndInvokeBenchmark(
212 gflags::ParseCommandLineFlags(&argc, &argv,
true);
A reference wrapper for callable objects.
—— Concurrent Priority Queue Implementation ——
int main(int argc, char **argv)
BENCHMARK(fbFollyGlobalBenchmarkBaseline)
auto makeUnpredictable(T &datum) -> typename std::enable_if< !detail::DoNotOptimizeAwayNeedsIndirect< T >::value >::type
auto doNotOptimizeAway(const T &datum) -> typename std::enable_if< !detail::DoNotOptimizeAwayNeedsIndirect< T >::value >::type