/*
- * Copyright 2012 Facebook, Inc.
+ * Copyright 2014 Facebook, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* limitations under the License.
*/
-#include "folly/ThreadCachedInt.h"
-#include "folly/Hash.h"
+#include <folly/ThreadCachedInt.h>
+#include <folly/Hash.h>
#include <atomic>
#include <thread>
#include <gtest/gtest.h>
#include <gflags/gflags.h>
#include <glog/logging.h>
-#include "folly/Benchmark.h"
+#include <folly/Benchmark.h>
using namespace folly;
ThreadLocal<int32_t> globalTL32Baseline;
std::atomic<int64_t> globalInt64Baseline(0);
std::atomic<int32_t> globalInt32Baseline(0);
-__thread int64_t global__thread64;
-__thread int32_t global__thread32;
+FOLLY_TLS int64_t global__thread64;
+FOLLY_TLS int32_t global__thread32;
-// Alternate lock-free implementation. Acheives about the same performance,
+// Alternate lock-free implementation. Achieves about the same performance,
// but uses about 20x more memory than ThreadCachedInt with 24 threads.
struct ShardedAtomicInt {
static const int64_t kBuckets_ = 2048;
std::atomic<int64_t> ints_[kBuckets_];
inline void inc(int64_t val = 1) {
- int bucket = hash::twang_mix64(pthread_self()) & (kBuckets_ - 1);
+ int bucket = hash::twang_mix64(
+ uint64_t(pthread_self())) & (kBuckets_ - 1);
std::atomic_fetch_add(&ints_[bucket], val);
}
REG_BASELINE(_thread32, global__thread32 += 1);
REG_BASELINE(ThreadLocal64, *globalTL64Baseline += 1);
REG_BASELINE(ThreadLocal32, *globalTL32Baseline += 1);
-REG_BASELINE(atomic_inc64, std::atomic_fetch_add(&globalInt64Baseline, 1L));
-REG_BASELINE(atomic_inc32, std::atomic_fetch_add(&globalInt32Baseline, 1));
+REG_BASELINE(atomic_inc64,
+ std::atomic_fetch_add(&globalInt64Baseline, int64_t(1)));
+REG_BASELINE(atomic_inc32,
+ std::atomic_fetch_add(&globalInt32Baseline, int32_t(1)));
REG_BASELINE(ShardedAtm64, shd_int64.inc());
BENCHMARK_PARAM(BM_mt_cache_size64, 0);
testing::InitGoogleTest(&argc, argv);
google::ParseCommandLineFlags(&argc, &argv, true);
google::SetCommandLineOptionWithMode(
- "bm_max_iters", "10000000", google::SET_FLAG_IF_DEFAULT
+ "bm_min_usec", "10000", google::SET_FLAG_IF_DEFAULT
);
if (FLAGS_benchmark) {
folly::runBenchmarks();