#include <benchmark/benchmark.h>
#include "ArenaAllocator.hpp"

static void bench_alloc_speed(benchmark::State& state)
{
	while (state.KeepRunning()) {
		Arena<sizeof(long double), 128, alignof(long double)> arena;
		for(auto&& i = state.range(0); i >= 0; i--)
		{
			void *ptr = arena.allocate(1);
			benchmark::ClobberMemory();
		}
	}
}

static void bench_alloc_baseline(benchmark::State& state)
{
	while (state.KeepRunning()) {
		Arena<sizeof(long double), 128, alignof(long double)> arena;
		benchmark::DoNotOptimize(arena);
	}
}

static void bench_malloc_speed(benchmark::State& state)
{
	while (state.KeepRunning()) {
		for(auto&& i = state.range(0); i >= 0; i--)
		{
			void *ptr;
			benchmark::DoNotOptimize(ptr = malloc(sizeof(long double)));
			free(ptr);
		}
	}
}

BENCHMARK(bench_alloc_baseline);
BENCHMARK(bench_alloc_speed)->Range(2, 128);
BENCHMARK(bench_malloc_speed)->Range(2, 128);

BENCHMARK_MAIN();
