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.
* Make --benchmark_list_tests respect --benchmark_format via reporter List() (#1642)
* Export FindBenchmarksInternal for shared-library test link; fix include order
* 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>
* 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>
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>
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>
* 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
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
* 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.
* `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.
* 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
* [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
* 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
* 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
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
* 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
* 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>
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.
}
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>
* 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.
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.
* 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>
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>
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>