+typedef junction::ConcurrentMap_Linear<size_t, size_t> LinearMap;
+typedef junction::ConcurrentMap_Leapfrog<size_t, size_t> LeapfrogMap;
+typedef junction::ConcurrentMap_Crude<size_t, size_t> CrudeMap;
+
+template <typename Map>
+void run_crude_map(size_t map_size, size_t pass_count, const char* bench_name,
+ size_t gc_frequency) {
+ std::cout << "[ RUN ] " << kTestName << "." << bench_name << "\n";
+ auto start_time = std::chrono::system_clock::now();
+
+ size_t nInsertedNum = 0;
+ size_t nFindSuccess = 0;
+ size_t nOperations = 0;
+ // Seems like the crude map won't resize, so better have a large enough
+ // capacity.
+ std::unique_ptr<Map> map(new Map(map_size * 32));
+ auto qsbrContext = junction::DefaultQSBR.createContext();
+ for (size_t count = 0; count < pass_count; count++) {
+ for (size_t i = 0; i < map_size; ++i) {
+ // The number to operate on the map.
+ size_t n = map_size + i;
+ // Insert
+ if (i % s_nInsertPercentage == 1) {
+ map->assign(i, n);
+ nInsertedNum++;
+// std::cout << "Inserted" << i << "\n";
+ }
+ // Find
+ {
+ if (map->get(i)) {
+ ++nFindSuccess;
+// std::cout << "Found" << i << "\n";
+ }
+ }
+ // Delete
+ if (i % s_nInsertPercentage == 1) {
+ if (map->get(i)) {
+ map->assign(n, 0);
+// std::cout << "Erased" << i << "\n";
+ }
+ }
+ if (++nOperations > gc_frequency) {
+ junction::DefaultQSBR.update(qsbrContext);
+ nOperations = 0;
+ }
+ }
+ }
+ junction::DefaultQSBR.update(qsbrContext);
+ junction::DefaultQSBR.destroyContext(qsbrContext );
+ auto finish_time = std::chrono::system_clock::now();
+ auto dur = finish_time - start_time;
+ auto milisecs = std::chrono::duration_cast<std::chrono::milliseconds>(dur);
+
+ if (nFindSuccess != nInsertedNum) {
+ std::cout << "nFindSuccess=" << nFindSuccess << ", nInsertedNum="
+ << nInsertedNum << "\n";
+ std::cout << "[ FAILED ] " << kTestName << "." << bench_name
+ << "(" << milisecs.count() << " ms)\n";
+ assert(false && "ConcurrentMap ERROR");
+ } else {
+ std::cout << "[ OK ] " << kTestName << "." << bench_name
+ << "(" << milisecs.count() << " ms)\n";
+ }
+}