diff --git a/main.cpp b/main.cpp index 20aac2c..a25397e 100644 --- a/main.cpp +++ b/main.cpp @@ -1,10 +1,61 @@ #include #include +#include +#include #include "amap.h" #include "simap.h" #include "mapmap.hpp" +/** + * Creates keys or returns the ith key. Used for performance tests. + * + * @param i When "create" is false, we return the ith key (does not check OOB) + * @param create When true, we initialize the keystore with keys generated from 0..i indices. + * @returns The ith key when create==false, otherwise undefined. + */ +inline const char *keystore(int i, bool create = false) noexcept { + static thread_local std::vector keys; + + if(!create) { + return keys[i].c_str(); + } else { + keys.resize(0); + keys.reserve(0); + std::string key = "k"; + for(int j = 0; j < i; ++j) { + keys.push_back(key + std::to_string(j)); + } + return NULL; + } +} + +/** + * Creates keys or returns the ith key. Used for performance tests. + * + * @param i When "create" is false, we return the ith data (does not check OOB) + * @param create When true, we initialize the datastore with datas generated from 0..i indices. + * @returns The ith data when create==false, otherwise undefined. + */ +inline int *datastore(int i, bool create = false) noexcept { + static thread_local std::vector keys; + + if(!create) { + return &(keys[i]); + } else { + keys.resize(0); + keys.reserve(0); + for(int j = 0; j < i; ++j) { + keys.push_back(j); + } + return NULL; + } +} + +void measure_speed(amap mapdo, void *map, int max_key) { +} + void test_basics(amap mapdo, void *map) { + /* Most basics */ assert(NULL == mapdo(map, AMAP_GET, "asdf", NULL)); int i = 42; int *iptr; @@ -45,12 +96,20 @@ void test_basics(amap mapdo, void *map) { } int main() { - /* test simap */ + /* Basic tests */ simap_instance si = simap_create(); test_basics(simap, &si); mapmap_instance mi = mapmap_create(); test_basics(mapmap, &mi); + /* Performance tests */ + int i = 1000; + keystore(i, true); + datastore(i, true); + + measure_speed(simap, &si, i); + measure_speed(mapmap, &mi, i); + return 0; }