/*
- * Copyright 2016 Facebook, Inc.
+ * Copyright 2017 Facebook, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
// @author: Xin Liu <xliux@fb.com>
#include <map>
+#include <memory>
#include <random>
#include <set>
#include <thread>
#include <folly/Benchmark.h>
#include <folly/ConcurrentSkipList.h>
-#include <folly/Hash.h>
#include <folly/RWSpinLock.h>
+#include <folly/hash/Hash.h>
#include <folly/portability/GFlags.h>
#include <glog/logging.h>
auto iter = a_set.begin();
for (int i = 0; i < iters; ++i) {
sum += *iter++;
- if (iter == a_set.end()) iter = a_set.begin();
+ if (iter == a_set.end()) {
+ iter = a_set.begin();
+ }
}
BENCHMARK_SUSPEND {
// VLOG(20) << "sum = " << sum;
auto iter = skipList.begin();
for (int i = 0; i < iters; ++i) {
sum += *iter++;
- if (iter == skipList.end()) iter = skipList.begin();
+ if (iter == skipList.end()) {
+ iter = skipList.begin();
+ }
}
BENCHMARK_SUSPEND {
int64_t mergedSum = 0;
FOR_EACH(it, a_set) {
- if (b_set.find(*it) != b_set.end()) mergedSum += *it;
+ if (b_set.find(*it) != b_set.end()) {
+ mergedSum += *it;
+ }
}
BENCHMARK_SUSPEND {
// VLOG(20) << mergedSum;
SkipListType::Skipper skipper(skipList2);
FOR_EACH(it, skipList) {
- if (skipper.to(*it)) mergedSum += *it;
+ if (skipper.to(*it)) {
+ mergedSum += *it;
+ }
}
BENCHMARK_SUSPEND {
for (int i = 0; i < FLAGS_num_sets; ++i) {
locks_[i] = new RWSpinLock();
- if (i > 0) sets_[i] = sets_[0];
+ if (i > 0) {
+ sets_[i] = sets_[0];
+ }
}
// This requires knowledge of the C++ library internals. Only use it if we're
} else {
skipListInsert(0, writeValues_[t]);
}
- return 0;
+ return false;
default:
return skipListFind(0, readValues_[t]);
}
} else {
setInsert(idx, writeValues_[t]);
}
- return 0;
+ return false;
default:
return setFind(idx, readValues_[t]);
}
static ConcurrentAccessData *mayInitTestData(int size) {
auto it = g_data.find(size);
if (it == g_data.end()) {
- auto ptr = std::shared_ptr<ConcurrentAccessData>(
- new ConcurrentAccessData(size));
+ auto ptr = std::make_shared<ConcurrentAccessData>(size);
g_data[size] = ptr;
return ptr.get();
}
BENCHMARK_PARAM(BM_ContentionCSL, 1048576);
BENCHMARK_DRAW_LINE();
-}
+} // namespace
int main(int argc, char** argv) {
google::InitGoogleLogging(argv[0]);