From 5e0c51e00c7b201dc290f036ec0ddcd6b47e528b Mon Sep 17 00:00:00 2001 From: Patrick Pelissier Date: Sat, 8 Apr 2017 22:28:24 +0200 Subject: [PATCH] Add test of dict over string. --- bench/bench-stl.cpp | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/bench/bench-stl.cpp b/bench/bench-stl.cpp index b936aaf2..a82ffb1d 100644 --- a/bench/bench-stl.cpp +++ b/bench/bench-stl.cpp @@ -7,6 +7,8 @@ #include #include #include +#include +#include #include #include @@ -190,6 +192,29 @@ test_dict_big(unsigned long n) g_result = s; } +/********************************************************************************************/ +static void +test_dict_str(unsigned long n) +{ + rand_init(); + unordered_map dict; + + for (size_t i = 0; i < n; i++) { + string s1 = static_cast( &(ostringstream() << rand_get()) )->str(); + string s2 = static_cast( &(ostringstream() << rand_get()) )->str(); + dict[s1] = s2; + } + rand_init(); + unsigned int s = 0; + for (size_t i = 0; i < n; i++) { + string s1 = static_cast( &(ostringstream() << rand_get()) )->str(); + unordered_map::iterator it = dict.find(s1); + if (it != dict.end()) + s ++; + } + g_result = s; +} + /********************************************************************************************/ static void test_sort(size_t n) @@ -222,4 +247,6 @@ int main(int argc, const char *argv[]) test_function("DictB time", 1000000, test_dict_big); if (n == 7) test_function("Sort time", 10000000, test_sort); + if (n == 8) + test_function("DictS time", 1000000, test_dict_str); }