Refactors RCU test cases
[folly.git] / folly / stress-test / stress-sequential-folly-sync.cpp
index 0b849c50d77c75d19f169b3a860245ce74a730b3..dbedef056312569483becf42445c344aaeaef8b3 100644 (file)
@@ -49,8 +49,8 @@ typedef folly::RWTicketSpinLock32 RWTicketSpinLock32;
 typedef folly::RWTicketSpinLock64 RWTicketSpinLock64;
 
 // RCU
-const size_t kRcuSyncPassCount = 3000000;
-const size_t kRcuNoSyncPassCount = 2500000;
+const size_t kRcuSyncPassCount = 180000;
+const size_t kRcuNoSyncPassCount = 3500000;
 const char* kRcuSyncBenchmarkName = "FollyRCU_Sync";
 const char* kRcuNoSyncBenchmarkName = "FollyRCU_NoSync";
 // Represent the RCU-protected data.
@@ -65,10 +65,18 @@ void run_rcu_sync(size_t pass_count, const char* bench_name) {
   std::cout << "[ RUN      ] " << kTestName << "." << bench_name << std::endl;
   auto start_time = std::chrono::system_clock::now();
 
-  for (size_t count = 0; count < pass_count; count++) {
-    RcuFoo* f = new RcuFoo();
-    folly::rcu_retire(f);
-    folly::synchronize_rcu();
+  for (int write_percentage = 1; write_percentage <= 5; write_percentage += 1) {
+    for (size_t count = 0; count < pass_count; count++) {
+      for (int i = 0; i < 100; ++i) {
+        if (i < write_percentage) {
+          RcuFoo* f = new RcuFoo();
+          folly::rcu_retire(f);
+          folly::synchronize_rcu();
+        } else {
+          folly::rcu_reader g;
+        }
+      }
+    }
   }
 
   auto finish_time = std::chrono::system_clock::now();
@@ -82,7 +90,7 @@ void run_rcu_no_sync(size_t pass_count, const char* bench_name) {
   std::cout << "[ RUN      ] " << kTestName << "." << bench_name << std::endl;
   auto start_time = std::chrono::system_clock::now();
 
-  for (int write_percentage = 5; write_percentage <= 10; write_percentage += 1) {
+  for (int write_percentage = 1; write_percentage <= 5; write_percentage += 1) {
     for (size_t count = 0; count < pass_count; count++) {
       for (int i = 0; i < 100; ++i) {
         if (i < write_percentage) {