Adds cross compile and test cases
[junction.git] / test / grampa_driver.cpp
diff --git a/test/grampa_driver.cpp b/test/grampa_driver.cpp
new file mode 100644 (file)
index 0000000..db2a276
--- /dev/null
@@ -0,0 +1,65 @@
+#include <junction/ConcurrentMap_Grampa.h>
+#include <iostream>
+#include <memory>
+#include <chrono>
+#include <cassert>
+
+namespace {
+
+const size_t kMapSize = 10000;
+const size_t kPassCount = 100000;
+const unsigned s_nInsertPercentage = 10;
+const char* kTestName = "InsDelFind";
+const char* kBenchmarkName = "JunctionMapLinear";
+
+} // namespace
+
+typedef junction::ConcurrentMap_Grampa<turf::u64, turf::u64> Map;
+
+int main() {
+    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) {
+            // The number to operate on the map.
+            size_t n = i;
+            // Insert
+            if (i % s_nInsertPercentage == 1) {
+                auto iter = map->insertOrFind(n);
+                if (!iter.getValue()) {
+                  iter.assignValue(n + 1);
+                  nInsertedNum++;
+//                  std::cout << "Inserted" << n << "\n";
+                }
+            }
+            // Find
+            {
+                auto iter = map->find(n);
+                if (!iter.getValue()) {
+                    ++nFindSuccess;
+//                    std::cout << "Found" << n << "\n";
+                }
+            }
+            // Delete
+            if (i % s_nInsertPercentage == 1) {
+                auto iter = map->find(n);
+                if (iter.getValue()) {
+                    iter.eraseValue();
+//                    std::cout << "Erased" << n << "\n";
+                }
+            }
+        }
+    }
+    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";
+
+    return 0;
+}