if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
# If this is the root project, issue a project() command so that
# the Visual Studio generator will create an .sln file.
- set(CMAKE_CONFIGURATION_TYPES "Debug;RelWithAsserts;RelWithDebInfo" CACHE INTERNAL "Build configs")
+ #set(CMAKE_CONFIGURATION_TYPES "Debug;RelWithAsserts;RelWithDebInfo" CACHE INTERNAL "Build configs")
+ set(CMAKE_CONFIGURATION_TYPES "RelWithDebInfo" CACHE INTERNAL "Build configs")
project(Junction)
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
set(JUNCTION_WITH_SAMPLES TRUE CACHE BOOL "Include all Junction samples in generated build system")
namespace {
-const size_t kMapSize = 10000;
-const size_t kPassCount = 100000;
const unsigned s_nInsertPercentage = 10;
const char* kTestName = "InsDelFind";
-const char* kBenchmarkName = "JunctionMapLinear";
+const size_t kGrampaMapSize = 20000;
+const size_t kGrampaPassCount = 30000;
+const char* kGrampaBenchmarkName = "JunctionMapLinear";
} // namespace
-typedef junction::ConcurrentMap_Grampa<turf::u64, turf::u64> Map;
+typedef junction::ConcurrentMap_Grampa<size_t, size_t> GrampaMap;
-int main() {
+template <typename Map>
+void run_test(size_t map_size, size_t pass_count, const char* bench_name) {
auto start_time = std::chrono::system_clock::now();
size_t nInsertedNum = 0;
size_t nFindSuccess = 0;
- std::unique_ptr<Map> map(new Map(kMapSize));
- for (size_t count = 0; count < kPassCount; count++) {
- for (size_t i = 1; i <= kMapSize; ++i) {
+ std::unique_ptr<Map> map(new Map());
+ 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 = i;
+ size_t n = map_size + i;
// Insert
if (i % s_nInsertPercentage == 1) {
auto iter = map->insertOrFind(n);
if (!iter.getValue()) {
- iter.assignValue(n + 1);
+ iter.assignValue(n);
nInsertedNum++;
// std::cout << "Inserted" << n << "\n";
}
// Find
{
auto iter = map->find(n);
- if (!iter.getValue()) {
+ if (iter.getValue()) {
++nFindSuccess;
// std::cout << "Found" << n << "\n";
}
// std::cout << "Erased" << n << "\n";
}
}
+ junction::DefaultQSBR.update(qsbrContext);
}
}
- assert(nFindSuccess == nFindSuccess && "junction::ConcurrentMap_Linear ERROR");
-
auto finish_time = std::chrono::system_clock::now();
auto dur = finish_time - start_time;
auto milisecs = std::chrono::duration_cast<std::chrono::milliseconds>(dur);
- std::cout << "[ OK ] " << kTestName << "." << kBenchmarkName << "("
- << milisecs.count() << " ms)\n";
+ 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";
+ }
+}
+
+int main() {
+ run_test<GrampaMap>(kGrampaMapSize, kGrampaPassCount, kGrampaBenchmarkName);
return 0;
}