From 904e2d1c0b2574e6f973321d9371efac11ee6c1b Mon Sep 17 00:00:00 2001 From: TinyAtoms Date: Wed, 5 Feb 2020 14:15:02 -0300 Subject: [PATCH] for real this time --- CMakeLists.txt | 2 +- main.cpp | 4 ++-- results.csv | 33 +++++++++++++++++++++++++++++++++ src/includes/aggregate_tests.h | 16 ++++++++++------ src/includes/tests.h | 12 +++++++----- 5 files changed, 53 insertions(+), 14 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 2e8fb68..3bdca81 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.15) project(another_studproject) set(CMAKE_CXX_STANDARD 17) -# set(CMAKE_CXX_FLAGS "-O3 -flto=thin -march=native") +set(CMAKE_CXX_FLAGS "-O3 -flto=thin -march=native") add_executable(another_studproject ./src/includes/generator.h ./src/generator.cpp diff --git a/main.cpp b/main.cpp index e3a5c2d..2a580f4 100644 --- a/main.cpp +++ b/main.cpp @@ -18,8 +18,8 @@ typedef std::unordered_map stringmap; int main() { time_point start_test = steady_clock::now(); // string_test(stringmap{}, 1); // process gets killed for sizes >35000 - int_test_aggregate(intmap{}, 2); - string_test_aggregate(stringmap{}, 2); + int_test_aggregate(intmap{}, 1); + string_test_aggregate(stringmap{}, 1); time_point end_test = steady_clock::now(); std::cout << "1 run all tests 1 map: " << duration_cast(end_test-start_test).count() << " minutes"; // test takes 52 mins for 10 runs for one hashmap diff --git a/results.csv b/results.csv index e69de29..fcc08f2 100644 --- a/results.csv +++ b/results.csv @@ -0,0 +1,33 @@ + +int_insert, 'std::unordered_map', 554, 591, 503, 498, 512, 526, 560, 564, 580 +int_succ_lookup, 'std::unordered_map', 435, 292, 312, 334, 354, 362, 383, 398, 413 +int_nosucc_lookup, 'std::unordered_map', 1571, 1800, 2700, 3538, 4559, 567, 6292, 596, 606 +int_delete, 'std::unordered_map', 428, 415, 461, 500, 510, 557, 561, 605, 615 +int_insert, 'std::unordered_map', 629, 459, 527, 498, 562, 541, 558, 557, 557 +int_succ_lookup, 'std::unordered_map', 404, 288, 342, 336, 357, 376, 396, 388, 392 +int_nosucc_lookup, 'std::unordered_map', 1608, 2003, 2863, 3699, 4624, 576, 6560, 586, 599 +int_delete, 'std::unordered_map', 532, 482, 479, 538, 519, 588, 587, 582, 591 +int_insert, 'std::unordered_map, std::__cxx11::basic_string >', 636, 644, 667, 728, 737, 727, 752, 750, 749 +int_succ_lookup, 'std::unordered_map, std::__cxx11::basic_string >', 432, 457, 472, 504, 506, 505, 537, 530, 519 +int_nosucc_lookup, 'std::unordered_map, std::__cxx11::basic_string >', 1139, 1675, 2395, 2933, 3777, 650, 4953, 660, 661 +int_delete, 'std::unordered_map, std::__cxx11::basic_string >', 762, 616, 648, 697, 693, 699, 736, 715, 713 +int_insert, 'std::unordered_map, std::__cxx11::basic_string >', 706, 696, 865, 841, 689, 687, 716, 709, 721 +int_succ_lookup, 'std::unordered_map, std::__cxx11::basic_string >', 582, 485, 799, 685, 495, 500, 537, 534, 518 +int_nosucc_lookup, 'std::unordered_map, std::__cxx11::basic_string >', 1124, 1752, 3944, 3627, 3532, 601, 5333, 620, 628 +int_delete, 'std::unordered_map, std::__cxx11::basic_string >', 672, 632, 1036, 797, 691, 691, 819, 727, 722 +int_insert, 'std::unordered_map', 138, 358, 194, 221, 228, 236, 257, 263, 262 +int_succ_lookup, 'std::unordered_map', 65, 202, 94, 107, 135, 114, 121, 120, 122 +int_nosucc_lookup, 'std::unordered_map', 358, 1158, 1226, 1606, 2330, 250, 2889, 306, 263 +int_delete, 'std::unordered_map', 166, 304, 229, 263, 282, 290, 310, 330, 328 +int_insert, 'std::unordered_map', 87, 240, 248, 218, 228, 241, 259, 254, 264 +int_succ_lookup, 'std::unordered_map', 37, 196, 101, 107, 114, 137, 136, 125, 124 +int_nosucc_lookup, 'std::unordered_map', 233, 885, 1243, 1595, 2097, 241, 4238, 265, 267 +int_delete, 'std::unordered_map', 95, 228, 256, 270, 287, 310, 571, 303, 351 +int_insert, 'std::unordered_map, std::__cxx11::basic_string >', 591, 534, 307, 370, 382, 382, 399, 405, 409 +int_succ_lookup, 'std::unordered_map, std::__cxx11::basic_string >', 189, 225, 264, 285, 287, 291, 302, 301, 308 +int_nosucc_lookup, 'std::unordered_map, std::__cxx11::basic_string >', 568, 2173, 1793, 2297, 2845, 376, 3789, 388, 384 +int_delete, 'std::unordered_map, std::__cxx11::basic_string >', 243, 828, 342, 365, 373, 375, 388, 386, 394 +int_insert, 'std::unordered_map, std::__cxx11::basic_string >', 350, 290, 296, 501, 942, 349, 340, 346, 355 +int_succ_lookup, 'std::unordered_map, std::__cxx11::basic_string >', 180, 237, 249, 385, 476, 289, 283, 288, 291 +int_nosucc_lookup, 'std::unordered_map, std::__cxx11::basic_string >', 665, 1202, 1745, 3419, 4709, 321, 3521, 332, 350 +int_delete, 'std::unordered_map, std::__cxx11::basic_string >', 246, 310, 322, 457, 1076, 353, 371, 373, 386 \ No newline at end of file diff --git a/src/includes/aggregate_tests.h b/src/includes/aggregate_tests.h index f7bc7b9..4ba4ae2 100644 --- a/src/includes/aggregate_tests.h +++ b/src/includes/aggregate_tests.h @@ -4,13 +4,14 @@ #include "./tests.h" #include #include +#include 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 }; // to print type info @@ -46,7 +47,7 @@ std::basic_string_view name(T var){ template void int_test_aggregate(T map, int runs){ std::ofstream output{"results.csv", std::ios_base::app}; - for (int i = 0; i < runs; ++i); + for (int i = 0; i < runs; ++i){ string insert = "\nint_insert, '"; string succ_lookup = "\nint_succ_lookup, '"; string nosucc_lookup = "\nint_nosucc_lookup, '"; @@ -57,7 +58,7 @@ void int_test_aggregate(T map, int runs){ nosucc_lookup += string{name(map)} +"'" ; delet += string{name(map)} + "'" ; for ( auto size : sizes){ - vector results = int_test(map, size); + vector results = int_test(map, size); insert += ", " + std::to_string(results[0]); succ_lookup += ", " + std::to_string(results[1]); @@ -67,6 +68,8 @@ void int_test_aggregate(T map, int runs){ output << insert << succ_lookup << nosucc_lookup << delet; cout << insert << succ_lookup << nosucc_lookup << delet; + } + } @@ -74,7 +77,7 @@ void int_test_aggregate(T map, int runs){ template void string_test_aggregate(T map, int runs){ std::ofstream output{"results.csv", std::ios_base::app}; - for (int i = 0; i < runs; ++i); + for (int i = 0; i < runs; ++i){ string insert = "\nint_insert, '"; string succ_lookup = "\nint_succ_lookup, '"; string nosucc_lookup = "\nint_nosucc_lookup, '"; @@ -85,16 +88,17 @@ void string_test_aggregate(T map, int runs){ nosucc_lookup += string{name(map)} +"'" ; delet += string{name(map)} + "'" ; for ( auto size : sizes){ - vector results = string_test(map, size); + vector results = string_test(map, size); insert += ", " + std::to_string(results[0]); succ_lookup += ", " + std::to_string(results[1]); nosucc_lookup +=", " + std::to_string(results[2]); delet += ", " + std::to_string(results[3]); + std::this_thread::sleep_for(seconds(5)); } output << insert << succ_lookup << nosucc_lookup << delet; cout << insert << succ_lookup << nosucc_lookup << delet; - + } } diff --git a/src/includes/tests.h b/src/includes/tests.h index fead026..1c26765 100644 --- a/src/includes/tests.h +++ b/src/includes/tests.h @@ -35,8 +35,8 @@ void prepare(google::sparse_hash_map& map, int size){ } template -vector int_test(T testmap, int size){ - vector results; // insert, lookup, unsuccesful lookup, delete times +vector int_test(T testmap, int size){ + vector results; // insert, lookup, unsuccesful lookup, delete times vector sample_keys; // get a sample of keys to lookup and later delete // unsuccesful lookup keys @@ -113,6 +113,7 @@ vector int_test(T testmap, int size){ time_point delete_end = steady_clock::now(); auto delete_time = (duration_cast(delete_end - delete_start) - vector_acces_time) / 10000; results.push_back(delete_time.count()); + testmap.clear(); return results; } @@ -122,8 +123,8 @@ vector int_test(T testmap, int size){ template -vector string_test(T map, int size){ - vector results; // insert, lookup, unsuccesful lookup, delete times +vector string_test(T map, int size){ + vector results; // insert, lookup, unsuccesful lookup, delete times vector sample_keys; // get a sample of keys to lookup and later delete // unsuccesful lookup keys @@ -182,7 +183,7 @@ vector string_test(T map, int size){ // unsuccesful lookup test time_point unlookup_start = steady_clock::now(); for (auto key : nonkeys){ - if (testmap[key] == "") cout << "WTF"; + if (testmap[key] == "a") cout << "WTF"; } time_point unlookup_end = steady_clock::now(); auto unlookup_time = (duration_cast(unlookup_end - unlookup_start) - vector_acces_time) / 10000 ; @@ -199,6 +200,7 @@ vector string_test(T map, int size){ time_point delete_end = steady_clock::now(); auto delete_time = (duration_cast(delete_end - delete_start) - vector_acces_time) / 10000; results.push_back(delete_time.count()); + testmap.clear(); return results; }