Rename ArenaAllocator -> Arena
This commit is contained in:
39
benchmarks/bench_arena.cpp
Normal file
39
benchmarks/bench_arena.cpp
Normal file
@@ -0,0 +1,39 @@
|
||||
#include "arena.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
|
||||
Arena arena;
|
||||
bench.run("Arena", [&] {
|
||||
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;
|
||||
}
|
||||
Reference in New Issue
Block a user