#include "arena_allocator.hpp"

#include <nanobench.h>
#include <vector>

int main() {
  // Small allocation benchmark - Arena vs malloc
  for (int alloc_size : {16, 64, 256, 1024}) {
    auto bench = ankerl::nanobench::Bench()
                     .title("Small Allocations (" + std::to_string(alloc_size) +
                            " bytes)")
                     .unit("allocation")
                     .warmup(100);

    {
      // Arena allocator benchmark
      ArenaAllocator arena;
      bench.run("ArenaAllocator", [&] {
        void *ptr = arena.allocate_raw(alloc_size);
        ankerl::nanobench::doNotOptimizeAway(ptr);
      });
    }

    {
      // Standard malloc benchmark
      std::vector<void *> malloc_ptrs;
      malloc_ptrs.reserve(1'000'000);
      bench.run("malloc", [&] {
        void *ptr = std::malloc(alloc_size);
        malloc_ptrs.push_back(ptr);
      });
      for (void *ptr : malloc_ptrs) {
        std::free(ptr);
      }
    }
  }

  return 0;
}
