Add test of dict over string.

This commit is contained in:
Patrick Pelissier committed 2017-04-08 22:28:24 +02:00
1 parent 4a9a8ebd3c
commit 5e0c51e00c
1 file changed
+27
+27
View File
@@ -7,6 +7,8 @@
#include <set>
#include <unordered_map>
#include <algorithm>
#include <string>
#include <sstream>
#include <stdlib.h>
#include <stdio.h>
@@ -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<string, string> dict;
for (size_t i = 0; i < n; i++) {
string s1 = static_cast<ostringstream*>( &(ostringstream() << rand_get()) )->str();
string s2 = static_cast<ostringstream*>( &(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*>( &(ostringstream() << rand_get()) )->str();
unordered_map<string, string>::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);
}