"Fossies" - the Fresh Open Source Software Archive

Member "ponyc-0.33.0/benchmark/libponyrt/mem/pool.cc" (1 Nov 2019, 6198 Bytes) of package /linux/misc/ponyc-0.33.0.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "pool.cc" see the Fossies "Dox" file reference documentation.

    1 #include <benchmark/benchmark.h>
    2 #include <platform.h>
    3 #include <mem/pool.h>
    4 
    5 #define LARGE_ALLOC ponyint_pool_adjust_size(POOL_MAX + 1)
    6 
    7 /// When we mmap, pull at least this many bytes.
    8 #ifdef PLATFORM_IS_ILP32
    9 #define POOL_MMAP (16 * 1024 * 1024) // 16 MB
   10 #else
   11 #define POOL_MMAP (128 * 1024 * 1024) // 128 MB
   12 #endif
   13 
   14 typedef char block_t[32];
   15 
   16 class PoolBench: public ::benchmark::Fixture
   17 { 
   18   protected:
   19     virtual void SetUp(const ::benchmark::State& st);
   20     virtual void TearDown(const ::benchmark::State& st);
   21 };
   22 
   23 void PoolBench::SetUp(const ::benchmark::State& st)
   24 {
   25   (void)st;
   26 }
   27 
   28 void PoolBench::TearDown(const ::benchmark::State& st)
   29 {
   30   (void)st;
   31 }
   32 
   33 BENCHMARK_DEFINE_F(PoolBench, pool_index)(benchmark::State& st) {
   34   while (st.KeepRunning()) {
   35     ponyint_pool_index(static_cast<size_t>(st.range(0)));
   36   }
   37   st.SetItemsProcessed(st.iterations());
   38 }
   39 
   40 BENCHMARK_REGISTER_F(PoolBench, pool_index)->RangeMultiplier(3)->Ranges({{1, 1024<<10}});
   41 
   42 BENCHMARK_DEFINE_F(PoolBench, POOL_ALLOC$)(benchmark::State& st) {
   43   while (st.KeepRunning()) {
   44     void* p = POOL_ALLOC(block_t);
   45     st.PauseTiming();
   46     POOL_FREE(block_t, p);
   47     st.ResumeTiming();
   48   }
   49   st.SetItemsProcessed(st.iterations());
   50 }
   51 
   52 BENCHMARK_REGISTER_F(PoolBench, POOL_ALLOC$);
   53 
   54 BENCHMARK_DEFINE_F(PoolBench, POOL_ALLOC_multiple$_)(benchmark::State& st) {
   55   size_t num_allocs = static_cast<size_t>(st.range(0));
   56   void** p = (void**)alloca(sizeof(void *) * num_allocs);
   57   while (st.KeepRunning()) {
   58     for(size_t i = 0; i < num_allocs; i++)
   59       p[i] = POOL_ALLOC(block_t);
   60     st.PauseTiming();
   61     for(size_t i = num_allocs; i > 0; i--)
   62       POOL_FREE(block_t, p[i-1]);
   63     st.ResumeTiming();
   64   }
   65   st.SetItemsProcessed(st.iterations()*num_allocs);
   66 }
   67 
   68 BENCHMARK_REGISTER_F(PoolBench, POOL_ALLOC_multiple$_)->Arg(1<<10);
   69 
   70 BENCHMARK_DEFINE_F(PoolBench, POOL_FREE$)(benchmark::State& st) {
   71   while (st.KeepRunning()) {
   72     st.PauseTiming();
   73     void* p = POOL_ALLOC(block_t);
   74     st.ResumeTiming();
   75     POOL_FREE(block_t, p);
   76   }
   77   st.SetItemsProcessed(st.iterations());
   78 }
   79 
   80 BENCHMARK_REGISTER_F(PoolBench, POOL_FREE$);
   81 
   82 BENCHMARK_DEFINE_F(PoolBench, POOL_ALLOC_FREE)(benchmark::State& st) {
   83   while (st.KeepRunning()) {
   84     void* p = POOL_ALLOC(block_t);
   85     POOL_FREE(block_t, p);
   86   }
   87   st.SetItemsProcessed(st.iterations());
   88 }
   89 
   90 BENCHMARK_REGISTER_F(PoolBench, POOL_ALLOC_FREE);
   91 
   92 BENCHMARK_DEFINE_F(PoolBench, POOL_FREE_multiple$_)(benchmark::State& st) {
   93   size_t num_allocs = static_cast<size_t>(st.range(0));
   94   void** p = (void**)alloca(sizeof(void *) * num_allocs);
   95   while (st.KeepRunning()) {
   96     st.PauseTiming();
   97     for(size_t i = 0; i < num_allocs; i++)
   98       p[i] = POOL_ALLOC(block_t);
   99     st.ResumeTiming();
  100     for(size_t i = num_allocs; i > 0; i--)
  101       POOL_FREE(block_t, p[i-1]);
  102   }
  103   st.SetItemsProcessed(st.iterations()*num_allocs);
  104 }
  105 
  106 BENCHMARK_REGISTER_F(PoolBench, POOL_FREE_multiple$_)->Arg(1<<10);
  107 
  108 BENCHMARK_DEFINE_F(PoolBench, POOL_ALLOC_FREE_multiple)(benchmark::State& st) {
  109   size_t num_allocs = static_cast<size_t>(st.range(0));
  110   void** p = (void**)alloca(sizeof(void *) * num_allocs);
  111   while (st.KeepRunning()) {
  112     for(size_t i = 0; i < num_allocs; i++)
  113       p[i] = POOL_ALLOC(block_t);
  114     for(size_t i = num_allocs; i > 0; i--)
  115       POOL_FREE(block_t, p[i-1]);
  116   }
  117   st.SetItemsProcessed(st.iterations()*num_allocs);
  118 }
  119 
  120 BENCHMARK_REGISTER_F(PoolBench, POOL_ALLOC_FREE_multiple)->Arg(1<<10);
  121 
  122 BENCHMARK_DEFINE_F(PoolBench, pool_alloc_size$)(benchmark::State& st) {
  123   while (st.KeepRunning()) {
  124     void* p = ponyint_pool_alloc_size(LARGE_ALLOC);
  125     st.PauseTiming();
  126     ponyint_pool_free_size(LARGE_ALLOC, p);
  127     st.ResumeTiming();
  128   }
  129   st.SetItemsProcessed(st.iterations());
  130 }
  131 
  132 BENCHMARK_REGISTER_F(PoolBench, pool_alloc_size$);
  133 
  134 BENCHMARK_DEFINE_F(PoolBench, pool_alloc_size_multiple$_)(benchmark::State& st) {
  135   size_t num_allocs = static_cast<size_t>(st.range(0));
  136   void** p = (void**)alloca(sizeof(void *) * num_allocs);
  137   while (st.KeepRunning()) {
  138     for(size_t i = 0; i < num_allocs; i++)
  139       p[i] = ponyint_pool_alloc_size(LARGE_ALLOC);
  140     st.PauseTiming();
  141     for(size_t i = num_allocs; i > 0; i--)
  142       ponyint_pool_free_size(LARGE_ALLOC, p[i-1]);
  143     st.ResumeTiming();
  144   }
  145   st.SetItemsProcessed(st.iterations()*num_allocs);
  146 }
  147 
  148 BENCHMARK_REGISTER_F(PoolBench, pool_alloc_size_multiple$_)->Arg((int)(POOL_MMAP/LARGE_ALLOC));
  149 
  150 BENCHMARK_DEFINE_F(PoolBench, pool_free_size$)(benchmark::State& st) {
  151   while (st.KeepRunning()) {
  152     st.PauseTiming();
  153     void* p = ponyint_pool_alloc_size(LARGE_ALLOC);
  154     st.ResumeTiming();
  155     ponyint_pool_free_size(LARGE_ALLOC, p);
  156   }
  157   st.SetItemsProcessed(st.iterations());
  158 }
  159 
  160 BENCHMARK_REGISTER_F(PoolBench, pool_free_size$);
  161 
  162 BENCHMARK_DEFINE_F(PoolBench, pool_alloc_free_size)(benchmark::State& st) {
  163   while (st.KeepRunning()) {
  164     void* p = ponyint_pool_alloc_size(LARGE_ALLOC);
  165     ponyint_pool_free_size(LARGE_ALLOC, p);
  166   }
  167   st.SetItemsProcessed(st.iterations());
  168 }
  169 
  170 BENCHMARK_REGISTER_F(PoolBench, pool_alloc_free_size);
  171 
  172 BENCHMARK_DEFINE_F(PoolBench, pool_free_size_multiple$_)(benchmark::State& st) {
  173   size_t num_allocs = static_cast<size_t>(st.range(0));
  174   void** p = (void**)alloca(sizeof(void *) * num_allocs);
  175   while (st.KeepRunning()) {
  176     st.PauseTiming();
  177     for(size_t i = 0; i < num_allocs; i++)
  178       p[i] = ponyint_pool_alloc_size(LARGE_ALLOC);
  179     st.ResumeTiming();
  180     for(size_t i = num_allocs; i > 0; i--)
  181       ponyint_pool_free_size(LARGE_ALLOC, p[i-1]);
  182   }
  183   st.SetItemsProcessed(st.iterations()*num_allocs);
  184 }
  185 
  186 BENCHMARK_REGISTER_F(PoolBench, pool_free_size_multiple$_)->Arg((int)(POOL_MMAP/LARGE_ALLOC));
  187 
  188 BENCHMARK_DEFINE_F(PoolBench, pool_alloc_free_size_multiple)(benchmark::State& st) {
  189   size_t num_allocs = static_cast<size_t>(st.range(0));
  190   void** p = (void**)alloca(sizeof(void *) * num_allocs);
  191   while (st.KeepRunning()) {
  192     for(size_t i = 0; i < num_allocs; i++)
  193       p[i] = ponyint_pool_alloc_size(LARGE_ALLOC);
  194     for(size_t i = num_allocs; i > 0; i--)
  195       ponyint_pool_free_size(LARGE_ALLOC, p[i-1]);
  196   }
  197   st.SetItemsProcessed(st.iterations()*num_allocs);
  198 }
  199 
  200 BENCHMARK_REGISTER_F(PoolBench, pool_alloc_free_size_multiple)->Arg((int)(POOL_MMAP/LARGE_ALLOC));