1 #include <junction/ConcurrentMap_Grampa.h>
9 const unsigned s_nInsertPercentage = 10;
10 const char* kTestName = "InsDelFind";
11 const size_t kGrampaMapSize = 20000;
12 const size_t kGrampaPassCount = 30000;
13 const char* kGrampaBenchmarkName = "JunctionMapLinear";
17 typedef junction::ConcurrentMap_Grampa<size_t, size_t> GrampaMap;
19 template <typename Map>
20 void run_test(size_t map_size, size_t pass_count, const char* bench_name) {
21 auto start_time = std::chrono::system_clock::now();
23 size_t nInsertedNum = 0;
24 size_t nFindSuccess = 0;
25 std::unique_ptr<Map> map(new Map());
26 auto qsbrContext = junction::DefaultQSBR.createContext();
27 for (size_t count = 0; count < pass_count; count++) {
28 for (size_t i = 0; i < map_size; ++i) {
29 // The number to operate on the map.
30 size_t n = map_size + i;
32 if (i % s_nInsertPercentage == 1) {
33 auto iter = map->insertOrFind(n);
34 if (!iter.getValue()) {
37 // std::cout << "Inserted" << n << "\n";
42 auto iter = map->find(n);
43 if (iter.getValue()) {
45 // std::cout << "Found" << n << "\n";
49 if (i % s_nInsertPercentage == 1) {
50 auto iter = map->find(n);
51 if (iter.getValue()) {
53 // std::cout << "Erased" << n << "\n";
56 junction::DefaultQSBR.update(qsbrContext);
59 auto finish_time = std::chrono::system_clock::now();
60 auto dur = finish_time - start_time;
61 auto milisecs = std::chrono::duration_cast<std::chrono::milliseconds>(dur);
63 if (nFindSuccess != nInsertedNum) {
64 std::cout << "nFindSuccess=" << nFindSuccess << ", nInsertedNum="
65 << nInsertedNum << "\n";
66 std::cout << "[ FAILED ] " << kTestName << "." << bench_name
67 << "(" << milisecs.count() << " ms)\n";
68 assert(false && "ConcurrentMap ERROR");
70 std::cout << "[ OK ] " << kTestName << "." << bench_name
71 << "(" << milisecs.count() << " ms)\n";
76 run_test<GrampaMap>(kGrampaMapSize, kGrampaPassCount, kGrampaBenchmarkName);