427 Commits

Author SHA1 Message Date
Vy Nguyen 1f5b0b0825 Make random number generator thread-local in perf_counters_gtest. (#2283)
Change the static std::mt19937 and std::uniform_int_distribution to thread_local in the do_work helper function to prevent data races when the benchmark is run with multiple threads.

Resolves ubsan/test failure
2026-08-07 05:10:07 +03:00
Tejas Anil Nagmote 977dfc2e3d Exclude setup/teardown from the MemoryManager measurement window (#2149) (#2276)
RunMemoryManager() opened the MemoryManager window before allocating the
ThreadManager and running the per-benchmark Setup(), and closed it after
Teardown(). Everything the library and the fixture allocate around the
benchmark was therefore attributed to the benchmark itself, so an exact
allocation count was impossible to obtain.

Move Start()/Stop() to bracket only RunInThread(), which is the same region
the timers cover. Setup()/Teardown() already run outside the timed region, so
this makes the memory window consistent with the time window.

Add memory_manager_ordering_gtest, which registers a MemoryManager that
records whether the window is open and asserts the fixture callbacks never
observe it as open. It fails on the previous ordering ("Teardown ran inside
the MemoryManager Start/Stop window") and passes with this change.
2026-08-03 14:27:00 +01:00
Mike Taves ff954e9ab8 Fix typos, add codespell configuration (#2262)
bazel / bazel.macos-latest (push) Has been cancelled
clang-format-lint / check-clang-format (push) Has been cancelled
clang-tidy / run-clang-tidy (push) Has been cancelled
doxygen / Build HTML documentation (push) Has been cancelled
python + Bazel pre-commit checks / pre-commit (push) Has been cancelled
sanitizer / asan.Debug (push) Has been cancelled
bazel / bazel.ubuntu-latest (push) Has been cancelled
bazel / bazel.windows-latest (push) Has been cancelled
build-and-test-min-cmake / macos-latest.min-cmake (push) Has been cancelled
build-and-test-min-cmake / ubuntu-latest.min-cmake (push) Has been cancelled
build-and-test-perfcounters / ubuntu-latest.Debug (push) Has been cancelled
build-and-test-perfcounters / ubuntu-latest.Release (push) Has been cancelled
build-and-test / macos-latest.Debug.shared.clang++ (push) Has been cancelled
build-and-test / ubuntu-22.04.Debug.shared.clang++ (push) Has been cancelled
build-and-test / ubuntu-24.04.Debug.shared.clang++ (push) Has been cancelled
build-and-test / ubuntu-24.04-arm.Debug.shared.clang++ (push) Has been cancelled
build-and-test / macos-latest.Debug.static.clang++ (push) Has been cancelled
build-and-test / ubuntu-22.04.Debug.static.clang++ (push) Has been cancelled
build-and-test / ubuntu-24.04.Debug.static.clang++ (push) Has been cancelled
build-and-test / ubuntu-24.04-arm.Debug.static.clang++ (push) Has been cancelled
build-and-test / macos-latest.Debug.shared.g++ (push) Has been cancelled
build-and-test / ubuntu-22.04.Debug.shared.g++ (push) Has been cancelled
build-and-test / ubuntu-24.04.Debug.shared.g++ (push) Has been cancelled
build-and-test / ubuntu-24.04-arm.Debug.shared.g++ (push) Has been cancelled
build-and-test / macos-latest.Debug.static.g++ (push) Has been cancelled
build-and-test / ubuntu-22.04.Debug.static.g++ (push) Has been cancelled
build-and-test / ubuntu-24.04.Debug.static.g++ (push) Has been cancelled
build-and-test / ubuntu-24.04-arm.Debug.static.g++ (push) Has been cancelled
build-and-test / macos-latest.Release.shared.clang++ (push) Has been cancelled
build-and-test / ubuntu-22.04.Release.shared.clang++ (push) Has been cancelled
build-and-test / ubuntu-24.04.Release.shared.clang++ (push) Has been cancelled
build-and-test / ubuntu-24.04-arm.Release.shared.clang++ (push) Has been cancelled
build-and-test / macos-latest.Release.static.clang++ (push) Has been cancelled
build-and-test / ubuntu-22.04.Release.static.clang++ (push) Has been cancelled
build-and-test / ubuntu-24.04.Release.static.clang++ (push) Has been cancelled
build-and-test / ubuntu-24.04-arm.Release.static.clang++ (push) Has been cancelled
build-and-test / macos-latest.Release.shared.g++ (push) Has been cancelled
build-and-test / ubuntu-22.04.Release.shared.g++ (push) Has been cancelled
build-and-test / ubuntu-24.04.Release.shared.g++ (push) Has been cancelled
build-and-test / ubuntu-24.04-arm.Release.shared.g++ (push) Has been cancelled
build-and-test / macos-latest.Release.static.g++ (push) Has been cancelled
build-and-test / ubuntu-22.04.Release.static.g++ (push) Has been cancelled
build-and-test / ubuntu-24.04.Release.static.g++ (push) Has been cancelled
build-and-test / ubuntu-24.04-arm.Release.static.g++ (push) Has been cancelled
build-and-test / windows-2022.Debug.shared.VS-17-2022 (push) Has been cancelled
build-and-test / windows-2022.Debug.static.VS-17-2022 (push) Has been cancelled
build-and-test / windows-2025.Debug.shared.VS-18-2025 (push) Has been cancelled
build-and-test / windows-2025.Debug.static.VS-18-2025 (push) Has been cancelled
build-and-test / windows-2022.Release.shared.VS-17-2022 (push) Has been cancelled
build-and-test / windows-2022.Release.static.VS-17-2022 (push) Has been cancelled
build-and-test / windows-2025.Release.shared.VS-18-2025 (push) Has been cancelled
build-and-test / windows-2025.Release.static.VS-18-2025 (push) Has been cancelled
build-and-test / windows-latest.Debug.shared.CLANG64 (push) Has been cancelled
build-and-test / windows-latest.Debug.shared.MINGW64 (push) Has been cancelled
build-and-test / windows-latest.Debug.shared.UCRT64 (push) Has been cancelled
build-and-test / windows-latest.Debug.static.CLANG64 (push) Has been cancelled
build-and-test / windows-latest.Debug.static.MINGW64 (push) Has been cancelled
build-and-test / windows-latest.Debug.static.UCRT64 (push) Has been cancelled
build-and-test / windows-latest.Release.shared.CLANG64 (push) Has been cancelled
build-and-test / windows-latest.Release.shared.MINGW64 (push) Has been cancelled
build-and-test / windows-latest.Release.shared.UCRT64 (push) Has been cancelled
build-and-test / windows-latest.Release.static.CLANG64 (push) Has been cancelled
build-and-test / windows-latest.Release.static.MINGW64 (push) Has been cancelled
build-and-test / windows-latest.Release.static.UCRT64 (push) Has been cancelled
sanitizer / msan.Debug (push) Has been cancelled
sanitizer / tsan.Debug (push) Has been cancelled
sanitizer / ubsan.Debug (push) Has been cancelled
sanitizer / asan.RelWithDebInfo (push) Has been cancelled
sanitizer / msan.RelWithDebInfo (push) Has been cancelled
sanitizer / tsan.RelWithDebInfo (push) Has been cancelled
sanitizer / ubsan.RelWithDebInfo (push) Has been cancelled
test-bindings / Test Python 3.10 bindings on macos-latest (push) Has been cancelled
test-bindings / Test Python 3.11 bindings on macos-latest (push) Has been cancelled
test-bindings / Test Python 3.12 bindings on macos-latest (push) Has been cancelled
test-bindings / Test Python 3.13 bindings on macos-latest (push) Has been cancelled
test-bindings / Test Python 3.10 bindings on ubuntu-latest (push) Has been cancelled
test-bindings / Test Python 3.11 bindings on ubuntu-latest (push) Has been cancelled
test-bindings / Test Python 3.12 bindings on ubuntu-latest (push) Has been cancelled
test-bindings / Test Python 3.13 bindings on ubuntu-latest (push) Has been cancelled
test-bindings / Test Python 3.10 bindings on windows-latest (push) Has been cancelled
test-bindings / Test Python 3.11 bindings on windows-latest (push) Has been cancelled
test-bindings / Test Python 3.12 bindings on windows-latest (push) Has been cancelled
test-bindings / Test Python 3.13 bindings on windows-latest (push) Has been cancelled
test-bindings / Test Rust bindings on macos-latest (push) Has been cancelled
test-bindings / Test Rust bindings on ubuntu-latest (push) Has been cancelled
test-bindings / Test Rust bindings on windows-latest (push) Has been cancelled
Fix typos
2026-07-24 05:57:53 +03:00
Tejas Anil Nagmote 8b66b54f7e Make --benchmark_list_tests respect --benchmark_format (#2245)
python + Bazel pre-commit checks / pre-commit (push) Has been cancelled
sanitizer / asan.Debug (push) Has been cancelled
clang-format-lint / check-clang-format (push) Has been cancelled
clang-tidy / run-clang-tidy (push) Has been cancelled
doxygen / Build HTML documentation (push) Has been cancelled
build-and-test-min-cmake / macos-latest.min-cmake (push) Has been cancelled
build-and-test-min-cmake / ubuntu-latest.min-cmake (push) Has been cancelled
build-and-test-perfcounters / ubuntu-latest.Debug (push) Has been cancelled
build-and-test-perfcounters / ubuntu-latest.Release (push) Has been cancelled
build-and-test / macos-latest.Debug.shared.clang++ (push) Has been cancelled
build-and-test / ubuntu-22.04.Debug.shared.clang++ (push) Has been cancelled
build-and-test / ubuntu-24.04.Debug.shared.clang++ (push) Has been cancelled
build-and-test / ubuntu-24.04-arm.Debug.shared.clang++ (push) Has been cancelled
build-and-test / macos-latest.Debug.static.clang++ (push) Has been cancelled
build-and-test / ubuntu-22.04.Debug.static.clang++ (push) Has been cancelled
build-and-test / ubuntu-24.04.Debug.static.clang++ (push) Has been cancelled
build-and-test / ubuntu-24.04-arm.Debug.static.clang++ (push) Has been cancelled
build-and-test / macos-latest.Debug.shared.g++ (push) Has been cancelled
build-and-test / ubuntu-22.04.Debug.shared.g++ (push) Has been cancelled
build-and-test / ubuntu-24.04.Debug.shared.g++ (push) Has been cancelled
bazel / bazel.macos-latest (push) Has been cancelled
bazel / bazel.ubuntu-latest (push) Has been cancelled
bazel / bazel.windows-latest (push) Has been cancelled
sanitizer / msan.Debug (push) Has been cancelled
build-and-test / ubuntu-24.04-arm.Debug.shared.g++ (push) Has been cancelled
build-and-test / macos-latest.Debug.static.g++ (push) Has been cancelled
build-and-test / ubuntu-22.04.Debug.static.g++ (push) Has been cancelled
build-and-test / ubuntu-24.04.Debug.static.g++ (push) Has been cancelled
build-and-test / ubuntu-24.04-arm.Debug.static.g++ (push) Has been cancelled
build-and-test / macos-latest.Release.shared.clang++ (push) Has been cancelled
build-and-test / ubuntu-22.04.Release.shared.clang++ (push) Has been cancelled
build-and-test / ubuntu-24.04.Release.shared.clang++ (push) Has been cancelled
build-and-test / ubuntu-24.04-arm.Release.shared.clang++ (push) Has been cancelled
build-and-test / macos-latest.Release.static.clang++ (push) Has been cancelled
build-and-test / ubuntu-22.04.Release.static.clang++ (push) Has been cancelled
build-and-test / ubuntu-24.04.Release.static.clang++ (push) Has been cancelled
build-and-test / ubuntu-24.04-arm.Release.static.clang++ (push) Has been cancelled
build-and-test / macos-latest.Release.shared.g++ (push) Has been cancelled
build-and-test / ubuntu-22.04.Release.shared.g++ (push) Has been cancelled
build-and-test / ubuntu-24.04.Release.shared.g++ (push) Has been cancelled
build-and-test / ubuntu-24.04-arm.Release.shared.g++ (push) Has been cancelled
build-and-test / macos-latest.Release.static.g++ (push) Has been cancelled
build-and-test / ubuntu-22.04.Release.static.g++ (push) Has been cancelled
build-and-test / ubuntu-24.04.Release.static.g++ (push) Has been cancelled
build-and-test / ubuntu-24.04-arm.Release.static.g++ (push) Has been cancelled
build-and-test / windows-2022.Debug.shared.VS-17-2022 (push) Has been cancelled
build-and-test / windows-2022.Debug.static.VS-17-2022 (push) Has been cancelled
build-and-test / windows-2025.Debug.shared.VS-18-2025 (push) Has been cancelled
build-and-test / windows-2025.Debug.static.VS-18-2025 (push) Has been cancelled
build-and-test / windows-2022.Release.shared.VS-17-2022 (push) Has been cancelled
build-and-test / windows-2022.Release.static.VS-17-2022 (push) Has been cancelled
build-and-test / windows-2025.Release.shared.VS-18-2025 (push) Has been cancelled
build-and-test / windows-2025.Release.static.VS-18-2025 (push) Has been cancelled
build-and-test / windows-latest.Debug.shared.CLANG64 (push) Has been cancelled
build-and-test / windows-latest.Debug.shared.MINGW64 (push) Has been cancelled
build-and-test / windows-latest.Debug.shared.UCRT64 (push) Has been cancelled
build-and-test / windows-latest.Debug.static.CLANG64 (push) Has been cancelled
build-and-test / windows-latest.Debug.static.MINGW64 (push) Has been cancelled
build-and-test / windows-latest.Debug.static.UCRT64 (push) Has been cancelled
build-and-test / windows-latest.Release.shared.CLANG64 (push) Has been cancelled
build-and-test / windows-latest.Release.shared.MINGW64 (push) Has been cancelled
build-and-test / windows-latest.Release.shared.UCRT64 (push) Has been cancelled
build-and-test / windows-latest.Release.static.CLANG64 (push) Has been cancelled
build-and-test / windows-latest.Release.static.MINGW64 (push) Has been cancelled
build-and-test / windows-latest.Release.static.UCRT64 (push) Has been cancelled
sanitizer / tsan.Debug (push) Has been cancelled
sanitizer / ubsan.Debug (push) Has been cancelled
sanitizer / asan.RelWithDebInfo (push) Has been cancelled
sanitizer / msan.RelWithDebInfo (push) Has been cancelled
sanitizer / tsan.RelWithDebInfo (push) Has been cancelled
sanitizer / ubsan.RelWithDebInfo (push) Has been cancelled
test-bindings / Test Python 3.10 bindings on macos-latest (push) Has been cancelled
test-bindings / Test Python 3.11 bindings on macos-latest (push) Has been cancelled
test-bindings / Test Python 3.12 bindings on macos-latest (push) Has been cancelled
test-bindings / Test Python 3.13 bindings on macos-latest (push) Has been cancelled
test-bindings / Test Python 3.10 bindings on ubuntu-latest (push) Has been cancelled
test-bindings / Test Python 3.11 bindings on ubuntu-latest (push) Has been cancelled
test-bindings / Test Python 3.12 bindings on ubuntu-latest (push) Has been cancelled
test-bindings / Test Python 3.13 bindings on ubuntu-latest (push) Has been cancelled
test-bindings / Test Python 3.10 bindings on windows-latest (push) Has been cancelled
test-bindings / Test Python 3.11 bindings on windows-latest (push) Has been cancelled
test-bindings / Test Python 3.12 bindings on windows-latest (push) Has been cancelled
test-bindings / Test Python 3.13 bindings on windows-latest (push) Has been cancelled
test-bindings / Test Rust bindings on macos-latest (push) Has been cancelled
test-bindings / Test Rust bindings on ubuntu-latest (push) Has been cancelled
test-bindings / Test Rust bindings on windows-latest (push) Has been cancelled
* Make --benchmark_list_tests respect --benchmark_format via reporter List() (#1642)

* Export FindBenchmarksInternal for shared-library test link; fix include order
2026-07-16 09:46:23 +01:00
dominic 64cc7cee5d better rust build/test (#2223) 2026-06-15 17:19:28 +01:00
dominic eb15fc80dd Introduce Rust bindings (#2221)
* add Rust bindings

* clang-format

* pre-commit fix

* windows static builds

* Rust prefers MD on windows

* check in lock file to avoid source poisoning

* use a rust crate name that isn't taken

* add CMake target for running Rust binding tests and integrate into CI

* complete crate rename

* enable test dependency downloads in Rust bindings CI
2026-06-15 14:29:03 +01:00
dominic 517b5d5622 Fix up windows tests (#2220)
* Replace VS 2022 (17) on 2025 with VS 2026 (18) on 2025

* Bring bazel tests in line with cmake wrt minimum times

* format BUILD
2026-06-11 11:13:38 +01:00
Alyssa Ross b5ba9bab85 Handle missing locale in test on more platforms (#2219)
* Add myself to AUTHORS and CONTRIBUTORS

* Improve accuracy of locale support check

It's much easier to list the two platforms libstdc++ does support
locale manipulation on than to try to exhaustively list the myriad
platforms where it does not.
2026-06-10 16:16:30 +01:00
Haihan Jiang 345756f1ae Skip perf counter tests when counters are unavailable (#2204)
This handles platforms where benchmark is built with libpfm, but the specific counters used by these tests cannot be opened.
2026-05-27 07:10:21 +03:00
Haihan Jiang d6303b29ba Skip errored runs when computing repetition statistics (#2199) 2026-05-26 21:39:48 +03:00
Ben Beasley 96c7ddc2c1 In PerfCountersTest.MultiThreaded, serialize worker threads (#2175)
Fixes https://github.com/google/benchmark/issues/2173

Co-authored-by: dominic <510002+dmah42@users.noreply.github.com>
2026-04-20 23:58:11 +03:00
Christoph Grüninger 4fa8072866 Fix two GCC 16 issues (#2164)
* [test] Mark unused variables

Found by GCC (-Wunused-but-set-variable).

* [utils] Add missing include for export macro
2026-04-05 21:52:15 +03:00
dominic fc8a082c60 feat: Add ScopedPauseTiming RAII helper (#2157)
* feat: Add ScopedPauseTiming RAII helper

Adds a new `benchmark::ScopedPauseTiming` class that provides a convenient
RAII-style mechanism for pausing and resuming benchmark timers.

This is less error-prone than manually calling `PauseTiming` and
`ResumeTiming`, as it guarantees that the timer is resumed when the
scope is exited.

- Added `ScopedPauseTiming` to `include/benchmark/state.h`.
- Added a new test `test/scoped_pause_test.cc` to verify the
  functionality and prevent regressions.
- Updated `test/CMakeLists.txt` to include the new test.
- Added documentation for the new feature in `docs/user_guide.md`.

* Bump astral-sh/setup-uv from 7.6.0 to 8.0.0 (#2160)

Bumps [astral-sh/setup-uv](https://github.com/astral-sh/setup-uv) from 7.6.0 to 8.0.0.
- [Release notes](https://github.com/astral-sh/setup-uv/releases)
- [Commits](https://github.com/astral-sh/setup-uv/compare/37802adc94f370d6bfd71619e3f0bf239e1f3b78...cec208311dfd045dd5311c1add060b2062131d57)

---
updated-dependencies:
- dependency-name: astral-sh/setup-uv
  dependency-version: 8.0.0
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Bump lukka/get-cmake from 4.3.0 to 4.3.1 (#2159)

Bumps [lukka/get-cmake](https://github.com/lukka/get-cmake) from 4.3.0 to 4.3.1.
- [Release notes](https://github.com/lukka/get-cmake/releases)
- [Changelog](https://github.com/lukka/get-cmake/blob/main/RELEASE_PROCESS.md)
- [Commits](https://github.com/lukka/get-cmake/compare/b78306120111dc2522750771cfd09ee7ca723687...ea83089aa35e08e459464341fe24ad024ee2466f)

---
updated-dependencies:
- dependency-name: lukka/get-cmake
  dependency-version: 4.3.1
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: dominic <510002+dmah42@users.noreply.github.com>

* Bump numpy from 2.4.3 to 2.4.4 in /tools (#2158)

Bumps [numpy](https://github.com/numpy/numpy) from 2.4.3 to 2.4.4.
- [Release notes](https://github.com/numpy/numpy/releases)
- [Changelog](https://github.com/numpy/numpy/blob/main/doc/RELEASE_WALKTHROUGH.rst)
- [Commits](https://github.com/numpy/numpy/compare/v2.4.3...v2.4.4)

---
updated-dependencies:
- dependency-name: numpy
  dependency-version: 2.4.4
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: dominic <510002+dmah42@users.noreply.github.com>

* handle move operators

* Use manual time instead of real time for better repeatability

---------

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2026-04-02 09:57:26 +01:00
dominic 6daf2dff6f Refactor/modularize headers (#2140)
* Split the benchmark monolithic header

* src uses modular headers

* updated tests to use split headers

* clang-format

* clang-format mistake

* fix exports

* suppress warnings on msvc

* fixing double pops and some more missing exports
2026-03-04 09:53:50 +00:00
dominic b8ea42b2de multiple fixes to avoid Windows x64 crashes (#2139)
* fix: cast size_t widths to int for variadic printer to avoid Windows x64 crashes

* extend minimum time as Windows can have a coarse timer

* vsnprintf can consume va_list so we need to copy it to avoid UB

* extend longer test runtime to other problematic tests
2026-03-04 08:33:14 +00:00
Ben King fbb750d797 Add BENCHMARK_NAMED macro for named benchmarks without lambda (#2135)
* Add BENCHMARK_NAMED macro for named benchmarks without lambda

  Closes #2128. BENCHMARK_CAPTURE creates a lambda even when no arguments
  are captured, causing compiler/linker scalability issues with thousands
  of benchmarks. BENCHMARK_NAMED provides the same func/name format but
  passes the function pointer directly (no lambda), consistent with the
  existing BENCHMARK macro.

* Move BENCHMARK_NAMED test to register_benchmark_test with name assertions

* Add Benjamin King to AUTHORS and CONTRIBUTORS

* Fix clang-format: remove trailing spaces from BENCHMARK_NAMED macro

* Fix clang-format: remove extra blank line left after test removal

---------

Co-authored-by: Roman Lebedev <lebedev.ri@gmail.com>
2026-02-27 12:01:58 +00:00
Peter Collingbourne 84732c8bb2 Replicate generic hardware events on all CPU PMUs (#2123)
On systems with more than one PMU for the CPUs (e.g. Apple M series SOCs),
generic hardware events are only created for an arbitrary PMU. Usually
this is the big cluster's PMU, which can cause inaccuracies when the
process is scheduled onto a little core. To fix this, teach PerfCounters
to register generic hardware events on all CPU PMUs.

CPU PMUs are identified using the same method as perf.
2026-02-11 10:07:17 +00:00
Dominic Hamon 31fae1bb24 rename to avoid gtest warnings 2026-01-20 10:51:58 +00:00
Jesse Rosenstock 90ebbdedf0 Make the Benchmark class public (#2101)
Move ::benchmark::internal::Benchmark to ::benchmark::Benchmark.

It's a bit odd that the documented way to pass arguments to a
benchmark is with `benchmark::internal::Benchmark`.  Make this
public instead.

https://github.com/google/benchmark/blob/v1.9.4/docs/user_guide.md#passing-arguments

https://raw.githubusercontent.com/google/benchmark/refs/tags/v1.9.4/docs/user_guide.md#:~:text=void%20CustomArguments(benchmark%3A%3A-,internal%3A%3ABenchmark,-*%20b)%20%7B%0A%20%20for%20(int

Keep ::benchmark::internal::Benchmark as a deprecated forwarding alias.
Uses of Benchmark in the internal namespace need to explicitly use
::benchmark::Benchmark to avoid the deprecation warning.
2026-01-14 21:04:17 +03:00
Frank Rosner 3e7dac665b #2080: Fix rate and thread rate counter aggregates (#2081)
* Update counter.cc

* User counters: normalize time by thread count

Fixes https://github.com/google/benchmark/issues/2080

* docs

---------

Co-authored-by: Roman Lebedev <lebedev.ri@gmail.com>
2025-12-10 21:38:32 +03:00
Roman Lebedev 1b150e2fb0 Add tests for user counters w/ threads (#2089) 2025-12-08 18:59:07 +00:00
wieDasDing 8498a2a039 Fix warnings from Clang (#2062)
* Fix warnings from Clang

This patch addresses a few issues:
- Wformat-nonliteral from colour printing functions
- Wmissing-prototypes from a few internal functions

Signed-off-by: Xiangfei Ding <dingxiangfei2009@protonmail.ch>

* Wrap tests in anonymous namespaces

Technically tests should be using internal linkage.

Signed-off-by: Xiangfei Ding <dingxiangfei2009@protonmail.ch>

---------

Signed-off-by: Xiangfei Ding <dingxiangfei2009@protonmail.ch>
2025-10-23 11:58:38 +03:00
dominic 2948b6a2e6 Adding explicit cast to aid in template argument deduction. (#2042)
* Adding explicit cast to aid in template argument deduction.

The `BENCHMARK(my_func)` macro needs to register the function my_func
so the library can run it. It uses `std::make_unique` to create an
object that stores metadata about the benchmark, including its name
("my_func") and a pointer to the function itself (my_func).

The specific constructor being called via `std::make_unique` is for
`benchmark::internal::FunctionBenchmark`.

When a benchmark function name is overloaded, the compiler can't
determine which function is being referred to until the call is made
with specific arguments, or enough context is provided.

The addition of a `static_cast` to the expected `Function*` type
resolves any ambiguity as the compiler is forced to pick the one with
the matching signature.

* clang-format

* add a test

* clang-format again
2025-09-16 16:14:09 +01:00
Roman Lebedev b2959a733d JSON reporter: make int dumping always happen in C locale (#2040)
The test fails without the fix.

Fixes https://github.com/google/benchmark/issues/2039
2025-09-15 09:53:26 +01:00
Roman Lebedev f02794a8bd Automatic ASLR disablement (#1978)
While ASLR is a useful security hardening feature,
it introduces unreproducible noise into benchmarks,
and we really really really don't want any noise,
especially easily avoidable one.

Unless prevented by some other security hardening,
we can disable ASLR for the current process,
and restart it, thus eliminating this noise.

Fixes https://github.com/google/benchmark/issues/461
2025-05-01 17:34:09 +01:00
Roman Lebedev b616354a76 Improve user UX on empty benchmarks (#1976)
Fixes https://github.com/google/benchmark/issues/1962
2025-05-01 13:46:23 +01:00
krzikalla f828d71c59 Method templates for Fixtures introduced (#1967) 2025-04-11 12:25:46 +01:00
krzikalla 0da57b85cf Threading api refactor (#1955)
Refactor the multi-threading api to support
using custom user-provided thread factory
instead of always spawning POSIX Threads.
2025-03-29 10:49:25 +03:00
Roman Lebedev 1bc59dce27 Finish cxx version bump (#1948)
* `CMakeLists.txt`: drop hopefully obsolete code

* README.md: update

* Unbreak `BENCHMARK_HAS_CXX11` macro

835365f99a stopped defining it,
but didn't un-conditionalize the code guarded under it...

* Drop `BENCHMARK_HAS_NO_VARIADIC_REGISTER_BENCHMARK`

We no longer support such an old gcc version

* `docs/user_guide.md`: proofread

* Add a test to ensure that `benchmark.h` remains C++14 header

* Revert `[[maybe_unused]]` changes - it requires C++17

* Also support C++11 standard for using the library

I don't think we want to support C++03 though,
but i suppose C++11 is palatable, at least right now.
2025-03-17 09:18:19 +00:00
EfesX 5a4c459548 fix memory manager result bug (#1941)
* fix memory manager result bug

* change is_valid to memory_iterations

* fix test

* some fixes

* fix test

...for msvc

* fix test

* fix test

add the correct explicitly casts

* fix msvc failure

* some fixes

* remove unnecessary include
2025-03-12 10:15:28 +00:00
EfesX ff5c94d860 change setup and teardown callback type (#1934)
Change type of callbacks to take `std::function`
2025-02-20 16:16:32 +03:00
dominic 951429282a [clang-tidy] resolve some global clang-tidy issues (#1933)
* [clang-tidy] resolve some global clang-tidy issues

* more nolint and some global fixes
2025-02-18 10:07:57 +00:00
dominic 57efbfb3a0 use smart pointers (#1935)
* use smart pointers
* use vectors
* size_t
2025-02-18 09:59:27 +00:00
dominic adbda82db3 [clang-tidy] autofix readability issues (#1931)
* [clang-tidy] autofix readability issues

* more modern clang format
2025-02-12 19:40:49 +00:00
dominic 2d4c8dd21a [clang-tidy] autofix cppcoreguidelines (#1932)
* [clang-tidy] autofix cppcoreguidelines

* better than automation maybe
2025-02-12 19:32:45 +00:00
dominic f8db7f6c07 [clang-tidy] fix missing braces (#1928)
* [clang-tidy] fix missing braces
2025-02-11 23:56:06 +00:00
dominic c68e308b4f [clang-tidy] fix warning about decaying array to pointer (#1926)
* [clang-tidy] fix warning about decaying array to pointer

* fix a different warning (old style cast)

* use string_view instead of old-style const char* strings

* ensure bazel windows is using c++17

* learn to use bazel

* and tests

* precommit fix

* more string_view creation and casting

* format

* format

* [clang-tidy] use unique_ptr for benchmark registration (#1927)

* use unique_ptr for benchmark registration
2025-02-11 23:15:20 +00:00
dominic 835365f99a remove cxx03 test, fully unblocking c++1X development (#1903)
* remove cxx03 test, fully unblocking c++1X development

* remove unnecessary macros

* pre-commit

* remove opt-in analyzer warnings from clang-tidy

* revert some changes, flush streams

* replace abort with exit(1) to call atexit and dtors

* remove more endl and put in explicit flush
2025-02-10 22:17:49 +00:00
Dominic Hamon 4642758438 fix some clang-tidy issues 2025-01-30 09:52:07 +00:00
xdje42 049f6e79cc [BUG] Run external profiler (ProfilerManager) same number of iterations #1913 (#1914)
Run the external profiler the same number of iterations as the
benchmark was run normally.
This makes, for example, a trace collected via ProfilerManager
consistent with collected PMU data.
2025-01-29 09:53:56 +00:00
dominic 62a321d6dc update standard to C++17 per C++ build support (#1875)
* update standard to C++17 per C++ build support

* disable deadcode checks from clang-tidy

* fix redundant definition of constexpr
2024-11-13 13:06:48 +00:00
xdje42 ffc727a859 Verify RegisterProfilerManager doesn't overwrite an existing registration (#1837)
* Verify RegisterProfilerManager doesn't overwrite an existing registration

Tested:
Add a second registration to test/profiler_manager_test.cc and
verify the test crashes as expected.

* Verify RegisterProfilerManager doesn't overwrite an existing registration

Tested:
Configure with:
cmake -GNinja -DCMAKE_BUILD_TYPE=Debug -DBENCHMARK_DOWNLOAD_DEPENDENCIES=on
Then run:
ctest -R profiler_manager_gtest
Before change test fails (expected), after change test passes (expected)

---------

Co-authored-by: dominic <510002+dmah42@users.noreply.github.com>
2024-10-24 10:22:58 +01:00
dominic 498714357f upgrade bazel mods. requires c++14 for tests (#1867) 2024-10-23 10:27:18 +01:00
xdje42 ebb5e3922d Move ProfilerManager Start/Stop routines closer to actual benchmark #1807 (#1818)
Previously, the Start/Stop routines were called before the benchmark function
was called and after it returned. However, what we really want is for them
to be called within the core of the benchmark:

  for (auto _ : state) {
    // This is what we want traced, not the entire BM_foo function.
  }
2024-08-01 08:42:41 +01:00
xdje42 7c8ed6b082 [FR] Add API to provide custom profilers #1807 (#1809)
This API is akin to the MemoryManager API and lets tools provide
their own profiler which is wrapped in the same way MemoryManager is
wrapped. Namely, the profiler provides Start/Stop methods that are called
at the start/end of running the benchmark in a separate pass.

Co-authored-by: dominic <510002+dmah42@users.noreply.github.com>
2024-07-16 09:56:40 +01:00
dominic c64b144f42 mitigate clang build warnings -Wconversion (#1763)
* mitigate clang build warnings -Wconversion

* ensure we have warnings set everywhere and fix some
2024-03-07 12:19:56 +00:00
Roman Lebedev ef88520d6f Revert "fix some warnings" (#1762)
This reverts commit 1576991177.
2024-03-06 12:40:31 +00:00
Dominic Hamon 1576991177 fix some warnings 2024-02-20 16:51:06 +00:00
Roman Lebedev 3d85343d65 Rewrite complexity_test to use (hardcoded) manual time (#1757)
* Rewrite complexity_test to use (hardcoded) manual time

This test is fundamentally flaky, because it tried to read tea leafs,
and is inherently misbehaving in CI environments,
since there are unmitigated sources of noise.

That being said, the computed Big-O also depends on the `--benchmark_min_time=`

Fixes https://github.com/google/benchmark/issues/272

* Correctly compute Big-O for manual timings. Fixes #1758.

* complexity_test: do more stuff in empty loop

* Make all empty loops be a bit longer empty

Looks like on windows, some of these tests still fail,
i guess clock precision is too small.
2024-02-19 15:22:35 +00:00
Sam James 385033bd11 CycleClock: Add support for Alpha architecture (#1753)
* Add support for Alpha architecture

As documented, the real cycle counter is unsafe to use here, because it
is a 32-bit integer which wraps every ~4s.  Use gettimeofday instead,
which has a limitation of a low-precision real-time-clock (~1ms), but no
wrapping.  Passes test suite.

Support parsing /proc/cpuinfo on Alpha

tabular_test: add a missing DoNotOptimize call
2024-02-14 00:04:44 +03:00