From 81dc4804ec298e6acc07682f2632e2060cf647fe Mon Sep 17 00:00:00 2001 From: TinyAtoms Date: Mon, 3 Feb 2020 19:21:35 -0300 Subject: [PATCH] made it use less memory --- main.cpp | 6 +++++- src/includes/aggregate_tests.h | 15 +++++++++++---- src/includes/tests.h | 13 ++++++++++--- 3 files changed, 26 insertions(+), 8 deletions(-) diff --git a/main.cpp b/main.cpp index 33125d1..e181d26 100644 --- a/main.cpp +++ b/main.cpp @@ -9,7 +9,11 @@ // typedef std::unordered_map map; +// we can use ^ to switch the map implementations to that +// we can add some cli handling so we can specify which maps to tests (or all) int main() { string_test(std::unordered_map{}, 10); int_test(std::unordered_map{}, 10); -} \ No newline at end of file + + // test takes 52 mins for 10 runs for 1 dict +} diff --git a/src/includes/aggregate_tests.h b/src/includes/aggregate_tests.h index 454e18f..6d7c6d4 100644 --- a/src/includes/aggregate_tests.h +++ b/src/includes/aggregate_tests.h @@ -10,7 +10,7 @@ std::vector sizes = { 50000, 100000, 150000, 200000, 250000, 300000, 350000, 400000, 500000, 600000, 700000, 800000, 900000, 1000000, 2000000, 3000000, 4000000, 5000000, 6000000, 7000000, 8000000, 9000000, 10000000, - 15000000, 20000000, 25000000, 30000000, 35000000, 40000000, 45000000, 50000000 + // 15000000, 20000000, 25000000, 30000000, 35000000, 40000000, 45000000, 50000000 }; @@ -47,18 +47,19 @@ std::basic_string_view name(T var){ template int int_test(T map, int repeats=30){ + std::cout << "\t\t" << name(map) << "int tests \n"; std::ofstream output{"results.csv", std::ios_base::app}; // insert int tests for (int i = 0; i < repeats; ++i){ std::string resultline = "insert_int, '" + std::string{name(map)} + "', "; for (auto size: sizes){ - std::cout << size << ", "; float result = insert_int_test(size, T{}).count(); resultline += std::to_string(result); resultline += ", "; } output << resultline << "\n"; } + std::cout << "insert int test done\n"; // lookup int for (int i = 0; i < repeats; ++i){ @@ -70,6 +71,7 @@ int int_test(T map, int repeats=30){ } output << resultline << "\n"; } + std::cout << "lookup int test done\n"; // unsuccesful lookup for (int i = 0; i < repeats; ++i){ std::string resultline = "nolookup_int, '" + std::string{name(map)} + "', "; @@ -80,6 +82,7 @@ int int_test(T map, int repeats=30){ } output << resultline << "\n"; } + std::cout << "unsuccesful lookup int test done\n"; // deletion for (int i = 0; i < repeats; ++i){ @@ -91,13 +94,14 @@ int int_test(T map, int repeats=30){ } output << resultline << "\n"; } - + std::cout << "deletion int test done\n"; return 0; } template int string_test(T map, int repeats=30){ + std::cout <<"\t\t" << name(map) << " stringtest \n"; std::ofstream output{"results.csv", std::ios_base::app}; // insert int tests for (int i = 0; i < repeats; ++i){ @@ -109,6 +113,7 @@ int string_test(T map, int repeats=30){ } output << resultline << "\n"; } + std::cout << "insert string test done\n"; // lookup int for (int i = 0; i < repeats; ++i){ @@ -120,6 +125,7 @@ int string_test(T map, int repeats=30){ } output << resultline << "\n"; } + std::cout << "lookup string test done\n"; // unsuccesful lookup for (int i = 0; i < repeats; ++i){ std::string resultline = "nolookup_string, '" + std::string{name(map)} + "', "; @@ -130,7 +136,7 @@ int string_test(T map, int repeats=30){ } output << resultline << "\n"; } - + std::cout << "unsuccesful lookup string test done\n"; // deletion for (int i = 0; i < repeats; ++i){ std::string resultline = "delete_string, '" + std::string{name(map)} + "', "; @@ -141,6 +147,7 @@ int string_test(T map, int repeats=30){ } output << resultline << "\n"; } + std::cout << "deletion string test done\n"; return 0; diff --git a/src/includes/tests.h b/src/includes/tests.h index 82e3ee8..b44331a 100644 --- a/src/includes/tests.h +++ b/src/includes/tests.h @@ -11,7 +11,8 @@ using namespace std::chrono; - +// writing out type info +// https://stackoverflow.com/questions/81870/is-it-possible-to-print-a-variables-type-in-standard-c/56766138#56766138 template nanoseconds insert_int_test(int size, T testmap){ // init hashmap, insert size - 10k items @@ -41,7 +42,7 @@ nanoseconds insert_int_test(int size, T testmap){ testmap.insert({i,i}); } time_point end_insert_test = steady_clock::now(); - + testmap.clear(); // time per insert auto duration = duration_cast(end_insert_test - start_insert_test) - vector_time ; return duration / 10000; @@ -78,7 +79,7 @@ nanoseconds insert_string_test(int size, T testmap){ testmap.insert({i,i}); } time_point end_insert_test = steady_clock::now(); - + testmap.clear(); // time per insert auto duration = duration_cast(end_insert_test - start_insert_test) - vector_time ; return duration / 10000; @@ -118,6 +119,7 @@ nanoseconds lookup_int_test(int size, T testmap){ std::cout << "SOMETHUNG IS WRONG!"; } } + testmap.clear(); time_point end_benchmark = steady_clock::now(); auto duration = duration_cast(end_benchmark - start_benchmark) - vector_time; return duration / 10000; @@ -156,6 +158,7 @@ nanoseconds lookup_string_test(int size, T testmap){ std::cout << "SOMETHUNG IS WRONG!"; } } + testmap.clear(); time_point end_benchmark = steady_clock::now(); auto duration = duration_cast(end_benchmark - start_benchmark) - vector_time; return duration / 10000; @@ -193,6 +196,7 @@ nanoseconds nolookup_int_test(int size, T testmap){ std::cout << "SOMETHUNG IS WRONG!"; } } + testmap.clear(); time_point end_benchmark = steady_clock::now(); auto duration = duration_cast(end_benchmark - start_benchmark) - vector_time; return duration / 10000; @@ -228,6 +232,7 @@ nanoseconds nolookup_string_test(int size, T testmap){ std::cout << "SOMETHUNG IS WRONG!"; } } + testmap.clear(); time_point end_benchmark = steady_clock::now(); auto duration = duration_cast(end_benchmark - start_benchmark) - vector_time; return duration / 10000; @@ -265,6 +270,7 @@ nanoseconds delete_int_test(int size, T testmap){ for (auto i : sample_inserted){ testmap.erase(i); } + testmap.clear(); time_point end_benchmark = steady_clock::now(); auto duration = duration_cast(end_benchmark - start_benchmark) - vector_time; return duration / 10000; @@ -302,6 +308,7 @@ nanoseconds delete_string_test(int size, T testmap){ for (auto i : sample_inserted){ testmap.erase(i); } + testmap.clear(); time_point end_benchmark = steady_clock::now(); auto duration = duration_cast(end_benchmark - start_benchmark) - vector_time; return duration / 10000;