Files
Toy/tests/benchmarks/array_allocation/bench_main.c
Kayne Ruse 223db840c8 Benchmarked memory models for Toy_Array, read more
The results can be found in
'tests/benchmarks/array_allocation/results.md'

The results are disappointing, as 'malloc()' is simply faster in every
possible situation compared to my custom arena allocator.
2024-12-24 10:37:54 +11:00

41 lines
1.0 KiB
C

#include "toy.h"
//util macros
#define TOY_ARRAY_EXPAND(array) ((array) = ((array) != NULL && (array)->count + 1 > (array)->capacity ? Toy_resizeArray((array), (array)->capacity * TOY_ARRAY_EXPANSION_RATE) : (array)))
#define TOY_ARRAY_PUSHBACK(array, value) (TOY_ARRAY_EXPAND(array), (array)->data[(array)->count++] = (value))
void stress_fillArray(Toy_Array** array) {
//Toy_Value is either 8 or 16 bytes
for (int i = 0; i < 10 * 1000 * 1000; i++) {
TOY_ARRAY_PUSHBACK(*array, TOY_VALUE_FROM_INTEGER(i));
}
}
int main() {
//Compare different memory strategies for Toy_Array
for (int i = 0; i < 100; i++) {
/*
//malloc
Toy_Array* array = Toy_resizeArray(NULL, TOY_ARRAY_INITIAL_CAPACITY);
stress_fillArray(&array);
Toy_resizeArray(array, 0);
/*/
//Toy_Bucket
benchBucket = Toy_allocateBucket(1024 * 1024 * 200); //200MB
Toy_Array* array = Toy_resizeArray(NULL, TOY_ARRAY_INITIAL_CAPACITY);
stress_fillArray(&array);
Toy_resizeArray(array, 0);
Toy_freeBucket(&benchBucket);
//*/
}
return 0;
}