| 123456789101112131415161718192021222324252627282930313233343536373839 |
- #include "core/small_obj.hpp"
- #include <benchmark/benchmark.h>
- #include <memory>
- template<size_t length>
- static void BM_std_shared_ptr(benchmark::State &state) {
- struct test_type {
- double data[length];
- };
- for (auto _: state) {
- benchmark::DoNotOptimize(std::make_shared<test_type>());
- }
- }
- BENCHMARK(BM_std_shared_ptr<0>);
- BENCHMARK(BM_std_shared_ptr<1>);
- BENCHMARK(BM_std_shared_ptr<8>);
- BENCHMARK(BM_std_shared_ptr<16>);
- BENCHMARK(BM_std_shared_ptr<128>);
- template<size_t length>
- static void BM_small_obj(benchmark::State &state) {
- struct test_type : public sophiar::small_obj<test_type> {
- double data[length];
- };
- for (auto _: state) {
- benchmark::DoNotOptimize(test_type::new_instance());
- }
- }
- BENCHMARK(BM_small_obj<0>);
- BENCHMARK(BM_small_obj<1>);
- BENCHMARK(BM_small_obj<8>);
- BENCHMARK(BM_small_obj<16>);
- BENCHMARK(BM_small_obj<128>);
- BENCHMARK_MAIN();
|