326 Commits

Author SHA1 Message Date
Tejas Anil Nagmote bb682b4d7f Fix use-after-free in CreateDefaultDisplayReporter (#2240) (#2265)
CreateDefaultDisplayReporter() transfers ownership of the returned
reporter to the caller, but cached that owning pointer in a
function-local static. After the first RunSpecifiedBenchmarks() call
destroyed the reporter, a subsequent call returned the same, now
dangling pointer, causing a heap-use-after-free in
BenchmarkReporter::GetOutputStream().

Return std::unique_ptr<BenchmarkReporter> so the ownership transfer is
expressed in the type, and drop the static so every call returns a
fresh reporter.
2026-08-03 10:27:41 +01: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
Haihan Jiang 6408acf50a Clarify DoNotOptimize const-ref warning (#2201)
Improve docs for `DoNotOptimize()`, and make it's compile-time diagnostic suggest a possible fix
2026-05-27 06:46:27 +03:00
qorex#dev b808118829 Replace deprecated _ReadWriteBarrier with std::atomic_signal_fence in MSVC path (#2177)
* Replace deprecated _ReadWriteBarrier with std::atomic_signal_fence

* use ClobberMemory() instead of inlining atomic_signal_fence

* add qorexdev to AUTHORS and CONTRIBUTORS

---------

Co-authored-by: dominic <510002+dmah42@users.noreply.github.com>
2026-04-24 17:09:22 +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
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
Kostiantyn Lazukin d8db2f90b6 Silence -Wc2y-extensions warning around __COUNTER__ (#2108)
clang-23 in pedantic mode now warns that __COUNTER__ macro is c2y
extension. This patch silences this warning around uses of this
macro.

Co-authored-by: dominic <510002+dmah42@users.noreply.github.com>
2026-01-21 13:15:42 +00:00
Dominic Hamon 5c55f5d4f4 clang tidy warnings 2026-01-20 10:37:18 +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
wieDasDing 9458f54b9a Take a closure for benchmark configuration (#2073)
It turns out it is useful when a benchmark is generated on the fly
before the enumeration on benchmark registration.

There is a use case in which benchmarks shall be built from
configuration flags.
Without captures, it is actually hard to pass additional data.

Signed-off-by: Xiangfei Ding <dingxiangfei2009@protonmail.ch>
2025-11-20 17:48:56 +00: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
Peter Collingbourne 5f7d66929f Add initializer for statistics field (#2038)
Copying uninitialized pointers is undefined behavior, and security
mitigations such as structure protection [1] take advantage of this.
Previously benchmarks would crash when copying the uninitialized
statistics field; fix the crash by initializing it.

[1] https://discourse.llvm.org/t/rfc-structure-protection-a-family-of-uaf-mitigation-techniques/85555
2025-09-12 04:24:44 +03:00
Tomasetti Romin f30ba8b993 core(perf): use string move constructor for AddCustomContext (#2005)
Signed-off-by: romintomasetti <romin.tomasetti@gmail.com>
2025-06-27 18:18:26 +03:00
A. Jiang 176ad6c20c Add deprecation warnings for MSVC (#1993)
* Add deprecation warnings for MSVC

* Split `DoNotOptimize` overloads for MSVC
2025-05-23 13:39:03 +03:00
Arseniy Terekhin 0d522831cf python binding: add range check (#1990)
fixes segmentation fault in ```import google_benchmark as benchmark
@benchmark.register
def av_test(state):
    state.range(9)
benchmark.main()
```
2025-05-21 09:21:35 +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 bc0989adee Detect and report ASLR status (#1977)
* Detect and report ASLR status

Theoretically, we could just disable ASLR in `main()`,
but that seems to be disallowed by default
by some other security features.

Refs. https://github.com/google/benchmark/issues/461

* Add a note about ASLR on other OS.
2025-05-01 17:32:16 +03:00
krzikalla ff52b227db Fixed private macro name issue (#1968) 2025-04-11 15:02:03 +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
dominic cb4239f398 Use the top-level ::benchmark namespace to resolve make_unique (#1960)
Fixes #1959
2025-03-27 08:22: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 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 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 05c5930d96 [clang-tidy] use unique_ptr for benchmark registration (#1927)
* use unique_ptr for benchmark registration
2025-02-11 21:10:34 +00:00
dominic 6a508bf11e benchmark declarations can and should be const (clang-tidy) (#1924)
* benchmark declarations can and should be const (clang-tidy)

* clang-format

* add clang-tidy ignore file to remove googletest (and other third party) source for consideration
2025-02-10 17:16:03 -08: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
Alecto Irene Perez 0c998f7cc4 Fix spurious warning 'misc-use-anonymous-namespace' (#1860) (#1861)
Disables 'misc-use-anonymous-namespace' for usage of the BENCHMARK
macro. This warning is spurious, and the variable declared by the
BENCHMARK macro can't be moved into an annonymous namespace.

We don't want to disable it globally, but it can be disabled locally,
for the `BENCHMARK` statement, as this warning appears downstream for
users.

See:
https://clang.llvm.org/extra/clang-tidy/#suppressing-undesired-diagnostics
2024-10-11 01:02:36 +03:00
Igor Zhukov c19cfee61e Fix C4459: Rename a function parameter profiler_manager to avoid hiding the global declaration. (#1839)
* Fix C4459: Rename a function parameter `profiler_manager` to avoid hiding the global declaration.

* Treat warnings as errors for MSVC

* disable one warning for MSVC
2024-08-19 06:39:37 +03:00
Chris Kennelly 6126d2a205 Align benchmark::State to a cacheline. (#1230)
* Align benchmark::State to a cacheline.

This can avoid interference with neighboring objects and stabilize
benchmark results.

* separate cachline definition from alignment attribute macro

Co-authored-by: Roman Lebedev <lebedev.ri@gmail.com>

---------

Co-authored-by: dominic <510002+dmah42@users.noreply.github.com>
Co-authored-by: Roman Lebedev <lebedev.ri@gmail.com>
2024-08-16 16:10: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
Dominic Hamon ad2b1c9ed1 clang format yet again 2024-07-17 16:49:12 +01:00
Dominic Hamon 299a8b881d clang format header fixes 2024-07-17 13:27: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
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
Matthias Liedtke b7ad5e0497 fix typo in GetBenchmarkVersion() (#1755) 2024-02-12 16:56:58 +00:00
Roman Lebedev e990563876 Add BENCHMARK_TEMPLATE[12]_CAPTURE, fusion of BENCHMARK_CAPTURE and BENCHMARK_TEMPLATE (#1747)
Test coverage isn't great, but not worse than the existing one.

You'd think `BENCHMARK_CAPTURE` would suffice,
but you can't pass `func<targs>` to it (due to the `<` and `>`),
and when passing `(func<targs>)` we get issues with brackets.
So i'm not sure if we can fully avoid this helper.

That being said, if there is only a single template argument,
`BENCHMARK_CAPTURE()` works fine if we avoid using function name.
2024-01-30 12:44:36 +00:00
Roman Lebedev 17bc235ab3 Output library / schema versions in JSON context block (#1742)
* CMake: `get_git_version()`: just use `--dirty` flag of `git describe`

* CMake: move version normalization out of `get_git_version()`

Mainly, i want `get_git_version()` to return true version,
not something sanitized.

* JSON reporter: store library version and schema version in `context`

* Tools: discard inputs with unexpected `json_schema_version`

* Extract version string into `GetBenchmarkVersiom()`

---------

Co-authored-by: dominic <510002+dmah42@users.noreply.github.com>
2024-01-29 13:15:43 +00:00
Roman Lebedev 50560985db [NFC] complexity_n is not of IterationCount type (#1709)
There is no bug here, but it gave me a scare the other day.
It is not incorrect to use `IterationCount` here,
since it's just an `int64_t` either way,
but it's wildly confusing. Let's not do that.

Co-authored-by: dominic <510002+dmah42@users.noreply.github.com>
2023-12-07 10:40:56 +00:00
Roman Lebedev 1e96bb0ab5 Support windows MSYS2 environments (#1704)
* [CI] Attempt to add windows MSYS2-based coverage

* Mark decl of `State::KeepRunningInternal()` as `inline`

Maybe helps with
```
D:\a\_temp\msys64\ucrt64\bin\g++.exe -DHAVE_STD_REGEX -DHAVE_STEADY_CLOCK -DTEST_BENCHMARK_LIBRARY_HAS_NO_ASSERTIONS -ID:/a/benchmark/benchmark/include -Wall  -Wextra  -Wshadow  -Wfloat-equal  -Wold-style-cast  -Werror  -pedantic  -pedantic-errors  -fstrict-aliasing  -Wno-deprecated-declarations  -Wno-deprecated  -Wstrict-aliasing  -Wno-unused-variable -std=c++11 -fvisibility=hidden -fno-keep-inline-dllexport   -UNDEBUG -MD -MT test/CMakeFiles/benchmark_test.dir/benchmark_test.cc.obj -MF test\CMakeFiles\benchmark_test.dir\benchmark_test.cc.obj.d -o test/CMakeFiles/benchmark_test.dir/benchmark_test.cc.obj -c D:/a/benchmark/benchmark/test/benchmark_test.cc
In file included from D:/a/benchmark/benchmark/test/benchmark_test.cc:1:
D:/a/benchmark/benchmark/include/benchmark/benchmark.h:1007:37: error: 'bool benchmark::State::KeepRunningInternal(benchmark::IterationCount, bool)' redeclared without dllimport attribute after being referenced with dll linkage [-Werror]
 1007 | inline BENCHMARK_ALWAYS_INLINE bool State::KeepRunningInternal(IterationCount n,
      |                                     ^~~~~
```

* Mark more `State`'s member function decls as `inline`

```
[27/110] Building CXX object test/CMakeFiles/spec_arg_verbosity_test.dir/spec_arg_verbosity_test.cc.obj
FAILED: test/CMakeFiles/spec_arg_verbosity_test.dir/spec_arg_verbosity_test.cc.obj
D:\a\_temp\msys64\clang32\bin\clang++.exe -DHAVE_STD_REGEX -DHAVE_STEADY_CLOCK -DHAVE_THREAD_SAFETY_ATTRIBUTES -DTEST_BENCHMARK_LIBRARY_HAS_NO_ASSERTIONS -ID:/a/benchmark/benchmark/include -Wall  -Wextra  -Wshadow  -Wfloat-equal  -Wold-style-cast  -Werror  -pedantic  -pedantic-errors  -Wshorten-64-to-32  -fstrict-aliasing  -Wno-deprecated-declarations  -Wno-deprecated  -Wstrict-aliasing  -Wthread-safety  -Wno-unused-variable -std=c++11 -fvisibility=hidden -fvisibility-inlines-hidden   -UNDEBUG -MD -MT test/CMakeFiles/spec_arg_verbosity_test.dir/spec_arg_verbosity_test.cc.obj -MF test\CMakeFiles\spec_arg_verbosity_test.dir\spec_arg_verbosity_test.cc.obj.d -o test/CMakeFiles/spec_arg_verbosity_test.dir/spec_arg_verbosity_test.cc.obj -c D:/a/benchmark/benchmark/test/spec_arg_verbosity_test.cc
In file included from D:/a/benchmark/benchmark/test/spec_arg_verbosity_test.cc:5:
D:/a/benchmark/benchmark/include/benchmark/benchmark.h:999:44: error: 'benchmark::State::KeepRunning' redeclared inline; 'dllimport' attribute ignored [-Werror,-Wignored-attributes]
  999 | inline BENCHMARK_ALWAYS_INLINE bool State::KeepRunning() {
      |                                            ^
D:/a/benchmark/benchmark/include/benchmark/benchmark.h:1003:44: error: 'benchmark::State::KeepRunningBatch' redeclared inline; 'dllimport' attribute ignored [-Werror,-Wignored-attributes]
 1003 | inline BENCHMARK_ALWAYS_INLINE bool State::KeepRunningBatch(IterationCount n) {
      |                                            ^
D:/a/benchmark/benchmark/include/benchmark/benchmark.h:1075:60: error: 'benchmark::State::begin' redeclared inline; 'dllimport' attribute ignored [-Werror,-Wignored-attributes]
 1075 | inline BENCHMARK_ALWAYS_INLINE State::StateIterator State::begin() {
      |                                                            ^
D:/a/benchmark/benchmark/include/benchmark/benchmark.h:1078:60: error: 'benchmark::State::end' redeclared inline; 'dllimport' attribute ignored [-Werror,-Wignored-attributes]

 1078 | inline BENCHMARK_ALWAYS_INLINE State::StateIterator State::end() {

      |                                                            ^

```

* StatisticsTest.CV: don't require precise FP match, tolerate some abs error

We get ever so slightly different results on windows with GCC.
```
71: Test command: D:\a\benchmark\benchmark\_build\test\statistics_gtest.exe
71: Working Directory: D:/a/benchmark/benchmark/_build/test
71: Test timeout computed to be: 10000000
71: Running main() from gmock_main.cc
71: [==========] Running 4 tests from 1 test suite.
71: [----------] Global test environment set-up.
71: [----------] 4 tests from StatisticsTest
71: [ RUN      ] StatisticsTest.Mean
71: [       OK ] StatisticsTest.Mean (0 ms)
71: [ RUN      ] StatisticsTest.Median
71: [       OK ] StatisticsTest.Median (0 ms)
71: [ RUN      ] StatisticsTest.StdDev
71: [       OK ] StatisticsTest.StdDev (0 ms)
71: [ RUN      ] StatisticsTest.CV
71: D:/a/benchmark/benchmark/test/statistics_gtest.cc:31: Failure
71: Expected equality of these values:
71:   benchmark::StatisticsCV({2.5, 2.4, 3.3, 4.2, 5.1})
71:     Which is: 0.32888184094918088
71:   0.32888184094918121
71: [  FAILED  ] StatisticsTest.CV (0 ms)
71: [----------] 4 tests from StatisticsTest (0 ms total)
```

* Fix DLL path discovery for tests
2023-11-23 17:47:04 +03:00
Afanasyev Ivan b40db86945 Fix unit tests compilation with non-gnu / non-msvc compilers with c++11 support. (#1691)
donotoptimize_test.cc could not be compiled under non-gnu / non-msvc compilers,
because only deprecated version of DoNotOptimize is available for these
compilers. Tests are compiled with -Werror. Patch fixes test compilation by
providing non-deprecated version of DoNotOptimize for compilers with c++11
standard support.

Co-authored-by: dominic <510002+dmah42@users.noreply.github.com>
2023-11-01 10:09:15 +00:00
dominic ca8d0f7b61 correct cli param in docs 2023-10-08 11:08:46 +01:00
Enrico Seiler e730f91d8c Fix passing non-const lvalue refs to DoNotOptimize (#1622) 2023-07-05 18:05:08 +01:00
Roman Lebedev edb0d3d46d Suppress intentional potential memory leak as detected by clang static analysis (#1618)
https://github.com/google/benchmark/issues/1513

Co-authored-by: dominic <510002+dmah42@users.noreply.github.com>
2023-07-03 10:18:31 +01:00
Bulat Gaifullin df9a99d998 Fix pass rvalue to DoNotOptimize (#1608)
* Fix pass rvalue to DoNotOptimize #1584

* Add test
2023-06-19 08:35:52 +01:00