chromium/base/threading/counter_perftest.cc

// Copyright 2021 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include <atomic>
#include <string>

#include "base/barrier_closure.h"
#include "base/functional/callback.h"
#include "base/memory/raw_ptr.h"
#include "base/synchronization/lock.h"
#include "base/synchronization/waitable_event.h"
#include "base/threading/simple_thread.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "testing/perf/perf_result_reporter.h"

// This file contains tests to measure the cost of incrementing:
// - A non-atomic variable, no lock.
// - A non-atomic variable, with lock.
// - An atomic variable, no memory barriers.
// - An atomic variable, acquire-release barriers.
// The goal is to provide data to guide counter implementation choices.

namespace base {

namespace {

constexpr char kMetricPrefixCounter[] =;
constexpr char kMetricOperationThroughput[] =;
constexpr uint64_t kNumIterations =;

perf_test::PerfResultReporter SetUpReporter(const std::string& story_name) {}

class Uint64_NoLock {};

class Uint64_Lock {};

class AtomicUint64_NoBarrier {};

class AtomicUint64_Barrier {};

template <typename CounterType>
class IncrementThread : public SimpleThread {};

template <typename CounterType>
void RunIncrementPerfTest(const std::string& story_name, int num_threads) {}

}  // namespace

TEST(CounterPerfTest, Uint64_NoLock_1Thread) {}

// No Uint64_NoLock_4Threads test because it would cause data races.

TEST(CounterPerfTest, Uint64_Lock_1Thread) {}

TEST(CounterPerfTest, Uint64_Lock_4Threads) {}

TEST(CounterPerfTest, AtomicUint64_NoBarrier_1Thread) {}

TEST(CounterPerfTest, AtomicUint64_NoBarrier_4Threads) {}

TEST(CounterPerfTest, AtomicUint64_Barrier_1Thread) {}

TEST(CounterPerfTest, AtomicUint64_Barrier_4Threads) {}

}  // namespace base