Expose move result from LockFreeRingBuffer::Cursor
[folly.git] / folly / test / ConcurrentSkipListBenchmark.cpp
index 9cd0e915b348c1cce4ce8ebfc26bbc45adde7801..fa5437c0e99e5e89e2e5b1b3e33bced1f3d24e5f 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright 2012 Facebook, Inc.
+ * Copyright 2015 Facebook, Inc.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
 #include <set>
 #include <thread>
 
-#include <boost/shared_ptr.hpp>
-
 #include <gflags/gflags.h>
 #include <glog/logging.h>
-#include "folly/Benchmark.h"
-#include "folly/ConcurrentSkipList.h"
-#include "folly/Hash.h"
-#include "folly/RWSpinLock.h"
+#include <folly/Benchmark.h>
+#include <folly/ConcurrentSkipList.h>
+#include <folly/Hash.h>
+#include <folly/RWSpinLock.h>
 
 
 DEFINE_int32(num_threads, 12, "num concurrent threads to test");
@@ -304,7 +302,7 @@ BENCHMARK(Accessor, iters) {
   auto sl = skiplist.get();
 
   susp.dismiss();
-  for (int i = 0; i < iters; ++i) {
+  for (size_t i = 0; i < iters; ++i) {
     SkipListAccessor accessor(sl);
   }
 }
@@ -320,7 +318,7 @@ BENCHMARK(accessorBasicRefcounting, iters) {
   l.init();
 
   susp.dismiss();
-  for (int i = 0; i < iters; ++i) {
+  for (size_t i = 0; i < iters; ++i) {
     value->fetch_add(1, std::memory_order_relaxed);
     if (dirty->load(std::memory_order_acquire) != 0) {
       folly::MSLGuard g(l);
@@ -352,6 +350,9 @@ class ConcurrentAccessData {
       if (i > 0) sets_[i] = sets_[0];
     }
 
+// This requires knowledge of the C++ library internals. Only use it if we're
+// using the GNU C++ library.
+#ifdef _GLIBCXX_SYMVER
     // memory usage
     int64_t setMemorySize = sets_[0].size() * sizeof(*sets_[0].begin()._M_node);
     int64_t cslMemorySize = 0;
@@ -362,6 +363,7 @@ class ConcurrentAccessData {
     LOG(INFO) << "size=" << sets_[0].size()
       << "; std::set memory size=" << setMemorySize
       << "; csl memory size=" << cslMemorySize;
+#endif
 
     readValues_.reserve(size);
     deleteValues_.reserve(size);
@@ -405,23 +407,23 @@ class ConcurrentAccessData {
     sets_[idx].erase(val);
   }
 
-  void runSkipList(int id, int iters) {
+  void runSkipList(int id, size_t iters) {
     int sum = 0;
-    for (int i = 0; i < iters; ++i) {
+    for (size_t i = 0; i < iters; ++i) {
       sum += accessSkipList(id, i);
     }
     // VLOG(20) << sum;
   }
 
-  void runSet(int id, int iters) {
+  void runSet(size_t id, size_t iters) {
     int sum = 0;
-    for (int i = 0; i < iters; ++i) {
+    for (size_t i = 0; i < iters; ++i) {
       sum += accessSet(id, i);
     }
     // VLOG(20) << sum;
   }
 
-  bool accessSkipList(int64_t id, int t) {
+  bool accessSkipList(int64_t id, size_t t) {
     if (t > readValues_.size()) {
       t = t % readValues_.size();
     }
@@ -439,7 +441,7 @@ class ConcurrentAccessData {
     }
   }
 
-  bool accessSet(int64_t id, int t) {
+  bool accessSet(int64_t id, size_t t) {
     if (t > readValues_.size()) {
       t = t % readValues_.size();
     }
@@ -468,12 +470,12 @@ class ConcurrentAccessData {
   std::vector<ValueType> deleteValues_;
 };
 
-static std::map<int, boost::shared_ptr<ConcurrentAccessData> > g_data;
+static std::map<int, std::shared_ptr<ConcurrentAccessData> > g_data;
 
 static ConcurrentAccessData *mayInitTestData(int size) {
   auto it = g_data.find(size);
   if (it == g_data.end()) {
-    auto ptr = boost::shared_ptr<ConcurrentAccessData>(
+    auto ptr = std::shared_ptr<ConcurrentAccessData>(
         new ConcurrentAccessData(size));
     g_data[size] = ptr;
     return ptr.get();
@@ -597,7 +599,7 @@ BENCHMARK_DRAW_LINE();
 
 int main(int argc, char** argv) {
   google::InitGoogleLogging(argv[0]);
-  google::ParseCommandLineFlags(&argc, &argv, true);
+  gflags::ParseCommandLineFlags(&argc, &argv, true);
 
   initData();
   runBenchmarks();