forked from MassiveAtoms/hashmap-bench
made it use less memory
This commit is contained in:
parent
90e3e0d274
commit
81dc4804ec
6
main.cpp
6
main.cpp
@ -9,7 +9,11 @@
|
|||||||
|
|
||||||
|
|
||||||
// typedef std::unordered_map<int,int> map;
|
// typedef std::unordered_map<int,int> 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() {
|
int main() {
|
||||||
string_test(std::unordered_map<std::string, std::string>{}, 10);
|
string_test(std::unordered_map<std::string, std::string>{}, 10);
|
||||||
int_test(std::unordered_map<int, int>{}, 10);
|
int_test(std::unordered_map<int, int>{}, 10);
|
||||||
}
|
|
||||||
|
// test takes 52 mins for 10 runs for 1 dict
|
||||||
|
}
|
||||||
|
@ -10,7 +10,7 @@ std::vector<int> sizes = {
|
|||||||
50000, 100000, 150000, 200000, 250000, 300000, 350000, 400000, 500000,
|
50000, 100000, 150000, 200000, 250000, 300000, 350000, 400000, 500000,
|
||||||
600000, 700000, 800000, 900000, 1000000,
|
600000, 700000, 800000, 900000, 1000000,
|
||||||
2000000, 3000000, 4000000, 5000000, 6000000, 7000000, 8000000, 9000000, 10000000,
|
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<char> name(T var){
|
|||||||
|
|
||||||
template<class T>
|
template<class T>
|
||||||
int int_test(T map, int repeats=30){
|
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};
|
std::ofstream output{"results.csv", std::ios_base::app};
|
||||||
// insert int tests
|
// insert int tests
|
||||||
for (int i = 0; i < repeats; ++i){
|
for (int i = 0; i < repeats; ++i){
|
||||||
std::string resultline = "insert_int, '" + std::string{name(map)} + "', ";
|
std::string resultline = "insert_int, '" + std::string{name(map)} + "', ";
|
||||||
for (auto size: sizes){
|
for (auto size: sizes){
|
||||||
std::cout << size << ", ";
|
|
||||||
float result = insert_int_test(size, T{}).count();
|
float result = insert_int_test(size, T{}).count();
|
||||||
resultline += std::to_string(result);
|
resultline += std::to_string(result);
|
||||||
resultline += ", ";
|
resultline += ", ";
|
||||||
}
|
}
|
||||||
output << resultline << "\n";
|
output << resultline << "\n";
|
||||||
}
|
}
|
||||||
|
std::cout << "insert int test done\n";
|
||||||
|
|
||||||
// lookup int
|
// lookup int
|
||||||
for (int i = 0; i < repeats; ++i){
|
for (int i = 0; i < repeats; ++i){
|
||||||
@ -70,6 +71,7 @@ int int_test(T map, int repeats=30){
|
|||||||
}
|
}
|
||||||
output << resultline << "\n";
|
output << resultline << "\n";
|
||||||
}
|
}
|
||||||
|
std::cout << "lookup int test done\n";
|
||||||
// unsuccesful lookup
|
// unsuccesful lookup
|
||||||
for (int i = 0; i < repeats; ++i){
|
for (int i = 0; i < repeats; ++i){
|
||||||
std::string resultline = "nolookup_int, '" + std::string{name(map)} + "', ";
|
std::string resultline = "nolookup_int, '" + std::string{name(map)} + "', ";
|
||||||
@ -80,6 +82,7 @@ int int_test(T map, int repeats=30){
|
|||||||
}
|
}
|
||||||
output << resultline << "\n";
|
output << resultline << "\n";
|
||||||
}
|
}
|
||||||
|
std::cout << "unsuccesful lookup int test done\n";
|
||||||
|
|
||||||
// deletion
|
// deletion
|
||||||
for (int i = 0; i < repeats; ++i){
|
for (int i = 0; i < repeats; ++i){
|
||||||
@ -91,13 +94,14 @@ int int_test(T map, int repeats=30){
|
|||||||
}
|
}
|
||||||
output << resultline << "\n";
|
output << resultline << "\n";
|
||||||
}
|
}
|
||||||
|
std::cout << "deletion int test done\n";
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
template<class T>
|
template<class T>
|
||||||
int string_test(T map, int repeats=30){
|
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};
|
std::ofstream output{"results.csv", std::ios_base::app};
|
||||||
// insert int tests
|
// insert int tests
|
||||||
for (int i = 0; i < repeats; ++i){
|
for (int i = 0; i < repeats; ++i){
|
||||||
@ -109,6 +113,7 @@ int string_test(T map, int repeats=30){
|
|||||||
}
|
}
|
||||||
output << resultline << "\n";
|
output << resultline << "\n";
|
||||||
}
|
}
|
||||||
|
std::cout << "insert string test done\n";
|
||||||
|
|
||||||
// lookup int
|
// lookup int
|
||||||
for (int i = 0; i < repeats; ++i){
|
for (int i = 0; i < repeats; ++i){
|
||||||
@ -120,6 +125,7 @@ int string_test(T map, int repeats=30){
|
|||||||
}
|
}
|
||||||
output << resultline << "\n";
|
output << resultline << "\n";
|
||||||
}
|
}
|
||||||
|
std::cout << "lookup string test done\n";
|
||||||
// unsuccesful lookup
|
// unsuccesful lookup
|
||||||
for (int i = 0; i < repeats; ++i){
|
for (int i = 0; i < repeats; ++i){
|
||||||
std::string resultline = "nolookup_string, '" + std::string{name(map)} + "', ";
|
std::string resultline = "nolookup_string, '" + std::string{name(map)} + "', ";
|
||||||
@ -130,7 +136,7 @@ int string_test(T map, int repeats=30){
|
|||||||
}
|
}
|
||||||
output << resultline << "\n";
|
output << resultline << "\n";
|
||||||
}
|
}
|
||||||
|
std::cout << "unsuccesful lookup string test done\n";
|
||||||
// deletion
|
// deletion
|
||||||
for (int i = 0; i < repeats; ++i){
|
for (int i = 0; i < repeats; ++i){
|
||||||
std::string resultline = "delete_string, '" + std::string{name(map)} + "', ";
|
std::string resultline = "delete_string, '" + std::string{name(map)} + "', ";
|
||||||
@ -141,6 +147,7 @@ int string_test(T map, int repeats=30){
|
|||||||
}
|
}
|
||||||
output << resultline << "\n";
|
output << resultline << "\n";
|
||||||
}
|
}
|
||||||
|
std::cout << "deletion string test done\n";
|
||||||
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -11,7 +11,8 @@
|
|||||||
|
|
||||||
using namespace std::chrono;
|
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 <class T>
|
template <class T>
|
||||||
nanoseconds insert_int_test(int size, T testmap){
|
nanoseconds insert_int_test(int size, T testmap){
|
||||||
// init hashmap, insert size - 10k items
|
// init hashmap, insert size - 10k items
|
||||||
@ -41,7 +42,7 @@ nanoseconds insert_int_test(int size, T testmap){
|
|||||||
testmap.insert({i,i});
|
testmap.insert({i,i});
|
||||||
}
|
}
|
||||||
time_point<steady_clock> end_insert_test = steady_clock::now();
|
time_point<steady_clock> end_insert_test = steady_clock::now();
|
||||||
|
testmap.clear();
|
||||||
// time per insert
|
// time per insert
|
||||||
auto duration = duration_cast<nanoseconds>(end_insert_test - start_insert_test) - vector_time ;
|
auto duration = duration_cast<nanoseconds>(end_insert_test - start_insert_test) - vector_time ;
|
||||||
return duration / 10000;
|
return duration / 10000;
|
||||||
@ -78,7 +79,7 @@ nanoseconds insert_string_test(int size, T testmap){
|
|||||||
testmap.insert({i,i});
|
testmap.insert({i,i});
|
||||||
}
|
}
|
||||||
time_point<steady_clock> end_insert_test = steady_clock::now();
|
time_point<steady_clock> end_insert_test = steady_clock::now();
|
||||||
|
testmap.clear();
|
||||||
// time per insert
|
// time per insert
|
||||||
auto duration = duration_cast<nanoseconds>(end_insert_test - start_insert_test) - vector_time ;
|
auto duration = duration_cast<nanoseconds>(end_insert_test - start_insert_test) - vector_time ;
|
||||||
return duration / 10000;
|
return duration / 10000;
|
||||||
@ -118,6 +119,7 @@ nanoseconds lookup_int_test(int size, T testmap){
|
|||||||
std::cout << "SOMETHUNG IS WRONG!";
|
std::cout << "SOMETHUNG IS WRONG!";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
testmap.clear();
|
||||||
time_point<steady_clock> end_benchmark = steady_clock::now();
|
time_point<steady_clock> end_benchmark = steady_clock::now();
|
||||||
auto duration = duration_cast<nanoseconds>(end_benchmark - start_benchmark) - vector_time;
|
auto duration = duration_cast<nanoseconds>(end_benchmark - start_benchmark) - vector_time;
|
||||||
return duration / 10000;
|
return duration / 10000;
|
||||||
@ -156,6 +158,7 @@ nanoseconds lookup_string_test(int size, T testmap){
|
|||||||
std::cout << "SOMETHUNG IS WRONG!";
|
std::cout << "SOMETHUNG IS WRONG!";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
testmap.clear();
|
||||||
time_point<steady_clock> end_benchmark = steady_clock::now();
|
time_point<steady_clock> end_benchmark = steady_clock::now();
|
||||||
auto duration = duration_cast<nanoseconds>(end_benchmark - start_benchmark) - vector_time;
|
auto duration = duration_cast<nanoseconds>(end_benchmark - start_benchmark) - vector_time;
|
||||||
return duration / 10000;
|
return duration / 10000;
|
||||||
@ -193,6 +196,7 @@ nanoseconds nolookup_int_test(int size, T testmap){
|
|||||||
std::cout << "SOMETHUNG IS WRONG!";
|
std::cout << "SOMETHUNG IS WRONG!";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
testmap.clear();
|
||||||
time_point<steady_clock> end_benchmark = steady_clock::now();
|
time_point<steady_clock> end_benchmark = steady_clock::now();
|
||||||
auto duration = duration_cast<nanoseconds>(end_benchmark - start_benchmark) - vector_time;
|
auto duration = duration_cast<nanoseconds>(end_benchmark - start_benchmark) - vector_time;
|
||||||
return duration / 10000;
|
return duration / 10000;
|
||||||
@ -228,6 +232,7 @@ nanoseconds nolookup_string_test(int size, T testmap){
|
|||||||
std::cout << "SOMETHUNG IS WRONG!";
|
std::cout << "SOMETHUNG IS WRONG!";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
testmap.clear();
|
||||||
time_point<steady_clock> end_benchmark = steady_clock::now();
|
time_point<steady_clock> end_benchmark = steady_clock::now();
|
||||||
auto duration = duration_cast<nanoseconds>(end_benchmark - start_benchmark) - vector_time;
|
auto duration = duration_cast<nanoseconds>(end_benchmark - start_benchmark) - vector_time;
|
||||||
return duration / 10000;
|
return duration / 10000;
|
||||||
@ -265,6 +270,7 @@ nanoseconds delete_int_test(int size, T testmap){
|
|||||||
for (auto i : sample_inserted){
|
for (auto i : sample_inserted){
|
||||||
testmap.erase(i);
|
testmap.erase(i);
|
||||||
}
|
}
|
||||||
|
testmap.clear();
|
||||||
time_point<steady_clock> end_benchmark = steady_clock::now();
|
time_point<steady_clock> end_benchmark = steady_clock::now();
|
||||||
auto duration = duration_cast<nanoseconds>(end_benchmark - start_benchmark) - vector_time;
|
auto duration = duration_cast<nanoseconds>(end_benchmark - start_benchmark) - vector_time;
|
||||||
return duration / 10000;
|
return duration / 10000;
|
||||||
@ -302,6 +308,7 @@ nanoseconds delete_string_test(int size, T testmap){
|
|||||||
for (auto i : sample_inserted){
|
for (auto i : sample_inserted){
|
||||||
testmap.erase(i);
|
testmap.erase(i);
|
||||||
}
|
}
|
||||||
|
testmap.clear();
|
||||||
time_point<steady_clock> end_benchmark = steady_clock::now();
|
time_point<steady_clock> end_benchmark = steady_clock::now();
|
||||||
auto duration = duration_cast<nanoseconds>(end_benchmark - start_benchmark) - vector_time;
|
auto duration = duration_cast<nanoseconds>(end_benchmark - start_benchmark) - vector_time;
|
||||||
return duration / 10000;
|
return duration / 10000;
|
||||||
|
Loading…
Reference in New Issue
Block a user