Commit Graph

1396 Commits

Author SHA1 Message Date
Vy Nguyen fec77322b4
Fix code triggering -Wsign-conversion (#1596)
* Fix code triggering -Wsign-conversion

* more test
2023-05-11 08:40:05 +01:00
Andy Christiansen 318dd44225
Disable debug-only test in release builds to avoid expected failures. (#1595)
Co-authored-by: Andy Christiansen <achristiansen@google.com>
2023-05-10 10:18:43 +01:00
Dominic Hamon 2dd015dfef update version to v1.8.0 2023-05-05 11:25:54 +01:00
dominic fba5dd147d
reenable msan sanitizer workflow (#1589) 2023-05-03 16:55:45 +01:00
Andrii Dushko b177433f3e
Guard NOMINMAX to prevent redefinition error (#1581) (#1582)
Fixes #1581.
2023-03-31 00:17:14 +03:00
Shiqing Yan f7547e29cc
Correct libpfm dep for integrators. (#1579) 2023-03-20 09:50:17 +00:00
pkasting d29044d5da
Fix compile warnings about ignoring a [[nodiscard]] type. (#1577)
Co-authored-by: dominic <510002+dmah42@users.noreply.github.com>
2023-03-16 11:07:13 +00:00
Dominic Hamon 4b086c26fe make libpfm dep work for integrators 2023-03-16 10:16:23 +00:00
Dominic Hamon 0c34d812e4 use 'new_git_repository' in external deps call to work with older bazel versions 2023-03-16 09:49:12 +00:00
dominic efc89f0b52
link to benchmark directly for tests that aren't link_main_test (#1576) 2023-03-14 13:35:32 +00:00
dominic 46d3c84518
Convert uses of `const char*` to `std::string` (#1567)
* Convert uses of const char* to std::string

* fix sanitizer builds

* reformat user guide

* include python bindings

* clang-format
2023-03-14 13:10:27 +00:00
dominic 68aa1903b1
add '@' to correctly reference build file for libpfm (#1575) 2023-03-14 10:18:00 +00:00
Henrique Bucher 9f7dc386be
Address warnings on NVIDIA nvc++ (#1573)
* Address warnings on NVIDIA nvc++

Types of warnings were being generated:
1. Deprecated warnings - solved by defining the relevant BENCHMARK_*
  macros for nvc++ and adding pragma suppress on a couple of .cc files
2. Setup/TearDown const vs non-const partial override - solved by
   adding non-const version
3. Static but not referenced - added diagnostic suppress for that file

* Modified manually to comply with CD/CI

* Revert partial override

* Suppress warnings from tests if compiler is NVHPC

---------

Co-authored-by: dominic <510002+dmah42@users.noreply.github.com>
2023-03-13 12:34:12 +00:00
Dominic Hamon 1b507cbf10 simplify setting C++ standard 2023-03-11 14:09:45 +00:00
Mike Apodaca f32748c372
[FR] Provide public accessors to benchmark name and arguments #1551 (#1563)
* [FR] Provide public accessors to benchmark name and arguments #1551

* Update AUTHORS and CONTRIBUTORS

* Update benchmark_register.cc

* Fix lint formatting
2023-03-10 12:38:11 +00:00
dominic 060d762d61
use std::string for skip messages (#1571) 2023-03-08 18:57:19 +00:00
Mike Apodaca adb0d3d0bf
[FR] state.SkipWithMessage #963 (#1564)
* Add `SkipWithMessage`

* Added `enum Skipped`

* Fix: error at end of enumerator list

* Fix lint errors

---------

Co-authored-by: dominic <510002+dmah42@users.noreply.github.com>
2023-03-08 18:24:48 +00:00
Henrique Bucher 4050b4bda5
Fix build break with nvc++ when -Werror is ON (#1569)
Build breaks when -Werror is turned on because of unhandled cases of
inocuous/pedantic warnings. Adopted the same solution as for Intel PGI
compiler - just disable -Werror manually, unless BENCHMARK_FORCE_WERROR
is enabled. Fixes #1556.
2023-03-08 09:50:30 +00:00
Marcel Jacobse f23fedbbf8
Fix examples in user guide using deprecated `DoNotOptimize`-API (#1568)
* Update AUTHORS/CONTRIBUTORS

* Fix examples with deprecated DoNotOptimize API

The const-reference API to DoNotOptimize was deprecated with #1493. Some
examples in the user guide are using exactly that deprecated interface.
This fixes that by passing non-const lvalues instead. Fixes #1566
2023-03-07 14:47:03 +00:00
Nicholas Junge 23dadfa4a7
Bump nanobind to stable v0.2.0, change linker options (#1565)
Bumps nanobind to v0.2.0, the latest stable version to include all
features needed to create the GBM bindings. Deprecated names in v0.2.0
were migrated to their new counterparts.

Linkopts for macOS were changed to mirror the "endorsed" linker options
used in nanobind's CMake config, which were changed since the last
commit.
2023-03-07 11:22:00 +00:00
Henrique Bucher fbc6efa9b5
Refactoring of PerfCounters infrastructure (#1559)
* Refactoring of PerfCounters infrastructure

The main feature in this pull request is the removal of the static
sharing of PerfCounters and instead creating them at the top
`RunBenchmarks()`  function where all benchmark runners are created. A
single PerfCountersMeasurement object is created and then shared with
all the new BenchmarkRunners objects, one per existing benchmark.

Other features conflated here in this PR are:
- Added BENCHMARK_DONT_OPTIMIZE macro in global scope
- Removal of the `IsValid()` query, being replaced by checking the
  number of remaining counters after validity tests
- Refactoring of all GTests to reflect the changes and new semantics
- extra comments throughout the new code to clarify intent

It was extremely hard to separate all those features in different PRs
as requested since they are so interdependent on each other so I'm just
pushing them altogether and asking for forgiveness.

This PR comes replacing PRs 1555 and 1558 which have been closed.

* Fixed whitespace issue with clang-format

My clang-format insists in deleting this single white space on line 601
while Github's clang format breaks when it is added. I had to disable
format-on-save to check-in this revert change.
I'm using clang 14.0.6.
2023-03-07 10:27:52 +00:00
dominic 9885aefb96
get rid of warnings in tests (#1562) 2023-03-06 14:47:54 +00:00
Henrique Bucher 2d5012275a
Filter performance counter names, not invalidate all (#1554)
* Filter performance counter names, not invalidate all

Currently, the performance counters are validated while they
are being created and one failure returns NoCounters(), ie it
effecitvely invalidates all the counters.

I would like to propose a new behavior: filter instead. If an
invalid name is added to the counter list, or if that particular
counter is not supported on this platform, that counter is dropped
from the list and an error messages is created, while all the
other counters remain active.

This will give testers a peace of mind that if one mistake is made
or if something is changed or removed from libpfm, their entire
test will not be invalidated. This feature gives more tolerance
with respect to versioning.

Another positive is that testers can now input a superset of all
desired counters for all platforms they support and just let
Benchmark drop all those that are not supported, although it will
create quite a lot of noise down the line, in which case perhaps
we should drop silently or make a consolidated, single error line
but this was not implemented in this change set.

* Removed unused helper type.
2023-03-02 14:56:13 +00:00
Henrique Bucher 27c1d8ace9
Implement unlimited number of performance counters (#1552)
* Implement unlimited number of performance counters

Linux performance counters will limit the number of hardware
counters per reading group. For that reason the implementation of
PerfCounters is limited to 3. However if only software counters
are added, there is no reason to limit the counters. For hardware
counters, we create multiple groups and store a vector or leaders
in the PerfCounters object. When reading, there is an extra time
waste by iterating through all the group leaders. However this
should be the same performance as with today. Reading is done by
groups and it had to be heavily adjusted with the logic being
moved to PerfCounterValues. I created a test for x86-64 and took
care of filtering out the events in case it runs in a platform
that does not support those counters - the test will not fail. The
current tests were already failing (ReOpenExistingCounters,
CreateExistingMeasurements and MultiThreaded) on the main branch
and they continue to fail after this implementation - I did not
fix those not to conflate all here.

* Moved the PerfCounterValues::Read() implementation from header to body.

* Added missing implementation of PerfCounters::IsCounterSupported when HAVE_LIBPFM is not defined.

* Changed comments to reflect the implementation

* Removed arg name so it does not generate an error when HAVE_LIBPBM is not defined.

* Made loop counter a const reference for clang-tidy

* Added missig BENCHMARK_EXPORT to PerfCounterValues
2023-03-01 15:30:41 +00:00
dominic c71d040549
add compiler to build-and-test and create min-cmake CI bot (#1550)
* add compiler to build-and-test and create min-cmake CI bot

* fix CXX env var

* downgrade msvc generator for cmake-3.10

* assume windows users have the latest cmake
2023-02-28 12:40:40 +00:00
Yingwei Zheng 3b19d7222d
Fix CPU frequency estimation on riscv (#1549)
* Fix CPU frequency estimation on riscv

* Cleanup code for CPU frequency estimation

* Fix use before definition of the macro

* Move the platform definitions back

* Fix compilation error on windows

* Remove unused sleep.h and sleep.cc
2023-02-21 11:30:28 +00:00
Carlos O'Ryan b111d01c1b
cleanup: support CMake >= 3.10 (#1544)
* cleanup: support CMake >= 3.10

This aligns the project with the CMake support policies in:

https://opensource.google/documentation/policies/cplusplus-support

I also simplied the management of CMake policies. Most of the overriden
policies (anything <= CMP0067) are enabled by default when you require
CMake >= 3.10.  But it is easier to just declare that you will accept
newer policies when they are available using the `...3.22` notation.

* Address review comments

* inlined links

---------

Co-authored-by: dominic <510002+dmah42@users.noreply.github.com>
2023-02-17 13:38:53 +00:00
dominic 1079d96989
Werror all the time (#1546) 2023-02-16 18:54:09 +00:00
Jonathon Reinhart 07996a8adc
Add missing parentheses in ParseBenchMinTime() (#1545)
The previous code was triggering a warning in Debug builds where NDEBUG
is not defined and BM_CHECK() is included:

  benchmark/src/benchmark_runner.cc: In function ‘benchmark::internal::BenchTimeType benchmark::internal::ParseBenchMinTime(const std::string&)’:
  benchmark/src/benchmark_runner.cc:212:24: error: suggest parentheses around ‘&&’ within ‘||’ [-Werror=parentheses]
    212 |            (has_suffix && *p_end == 's' || *p_end == '\0'))
        |             ~~~~~~~~~~~^~~~~~~~~~~~~~~~
  benchmark/src/check.h:82:4: note: in definition of macro ‘BM_CHECK’
     82 |   (b ? ::benchmark::internal::GetNullLogInstance()                           \
        |    ^

Add parenthesis around the && expression.

Also fix a spelling error and move the comma in the preceding comment to
improve clarity.

Tested:
- cmake -E make_directory build
- cmake -E chdir "build" cmake -DBENCHMARK_DOWNLOAD_DEPENDENCIES=on -DCMAKE_BUILD_TYPE=Debug ../
- cmake --build "build" --config Debug
- cmake -E chdir "build" ctest --build-config Debug
2023-02-16 18:35:21 +00:00
Yury Fedorov bd721f9859
Removing warnings appearing with C++20 / CLang 15 (#1542)
* Removing warnings appearing with C++20 / CLang 15

```
[ 70%] Building CXX object _deps/benchmark-build/test/CMakeFiles/benchmark_min_time_flag_time_test.dir/benchmark_min_time_flag_time_test.cc.o
/home/xxx/cpp/_deps/benchmark-src/test/benchmark_min_time_flag_time_test.cc:31:55: warning: unused parameter 'has_explicit_iters' [-Wunused-parameter]
  virtual void ReportRunsConfig(double min_time, bool has_explicit_iters,
                                                      ^
/home/xxx/cpp/_deps/benchmark-src/test/benchmark_min_time_flag_time_test.cc:32:48: warning: unused parameter 'iters' [-Wunused-parameter]
                                IterationCount iters) BENCHMARK_OVERRIDE {
                                               ^
2 warnings generated.
```

```
[ 70%] Building CXX object _deps/benchmark-build/test/CMakeFiles/benchmark_min_time_flag_iters_test.dir/benchmark_min_time_flag_iters_test.cc.o
/home/xxx/cpp/_deps/benchmark-src/test/benchmark_min_time_flag_iters_test.cc:22:36: warning: implicit conversion loses integer precision: 'const benchmark::IterationCount' (aka 'const long') to 'std::vector<int>::value_type' (aka 'int') [-Wshorten-64-to-32]
    iter_nums_.push_back(report[0].iterations);
               ~~~~~~~~~ ~~~~~~~~~~^~~~~~~~~~
1 warning generated.
```

* Refactoring to get the proper type of collection

* Refactoring to get the proper type of collection

* clang format

* bug fix in main
2023-02-13 11:18:07 +00:00
dominic 0ce66c00f5
update github actions to latest versions (#1541) 2023-02-09 15:52:03 +00:00
dominic 6ebd82f2be
replace complexity with simplicity for faster libc++ setup (#1539)
* replace complexity with simplicity for faster libc++ setup

* fix script reference

* ignore error from stdlib in clang+asan

* add missing run
2023-02-09 15:29:10 +00:00
hamptonm1 84c71faa81
Refactor links which include "master" and change it to "main" (#1540)
* Refactor URL links: remove "master"

* Replace "master" with "main"
2023-02-07 15:10:30 +00:00
Vy Nguyen 6cf7725ea1
Allow specifying number of iterations via --benchmark_min_time. (#1525)
* Allow specifying number of iterations via --benchmark_min_time.

Make the flag accept two new suffixes:
 + <integer>x: number of iterations
 + <floag>s: minimum number of seconds.

This matches the internal benchmark API.

* forgot to change flag type to string

* used tagged union instead of std::variant, which is not available pre C++14

* update decl in benchmark_runner.h too

* fixed errors

* refactor

* backward compat

* typo

* use IterationCount type

* fixed test

* const_cast

* ret type

* remove extra _

* debug

* fixed bug from reporting that caused the new configs not to be included in the final report

* addressed review comments

* restore unnecessary changes in test/BUILD

* fix float comparisons warnings from Release builds

* clang format

* fix visibility warning

* remove misc file

* removed  backup files

* addressed review comments

* fix shorten in warning

* use suffix for existing min_time specs to silent warnings in tests

* fix leaks

* use default min-time value in flag decl for consistency

* removed double kMinTimeDecl from benchmark.h

* dont need to preserve errno

* add death tests

* Add BENCHMARK_EXPORT to hopefully fix missing def errors

* only enable death tests in debug mode because bm_check is no-op in release mode

* guard death tests with additional support-check macros

* Add additional guard to prevent running in Release mode

---------

Co-authored-by: dominic <510002+dmah42@users.noreply.github.com>
2023-02-07 11:45:18 +00:00
Matt Armstrong 6bc17754f6
Support --benchmarks_filter in the compare.py 'benchmarks' command (#1486)
Previously compare.py ignored the --benchmarks_filter
argument when loading JSON.  This defeated any workflow when
a single run of the benchmark was run, followed by multiple
"subset reports" run against it with the 'benchmarks'
command.

Concretely this came up with the simple case:

 compare.py benchmarks a.json b.json --benchmarks_filter=BM_Example

This has no practical impact on the 'filters' and
'benchmarkfiltered' comand, which do their thing at a later
stage.

Fixes #1484

Co-authored-by: dominic <510002+dmah42@users.noreply.github.com>
2023-02-06 16:57:07 +00:00
Dominic Hamon f15f332fd1 get rid of some deprecation warnings from tests 2023-02-06 16:38:53 +00:00
dominic ff8d44c928
fix #1446 by removing the address operator (#1538)
* fix #1446 by removing the address operator

* add test

* format

---------

Co-authored-by: Thomas <thomas.maierbacher@rohde-schwarz.com>
Co-authored-by: Dominic Hamon <dominichamon@users.noreply.github.com>
2023-02-06 16:34:47 +00:00
JbR 4c9cee34f2
Fixing issue with ARM64EC and MSVC (#1514)
Co-authored-by: dominic <510002+dmah42@users.noreply.github.com>
2023-02-06 15:58:14 +00:00
Chris Kennelly 53df805dc8
Deprecate constant reference API to DoNotOptimize. (#1493)
The compiler assume that a constant reference, even though escaped via asm
volatile, is unchanged.  The const-ref interface is deprecated to discourage
new uses of it, as subtle compiler optimizations (invariant hoisting, etc.) can
occur.

Within microbenchmarks for Abseil's hashtables, BM_FindMiss_Hot
(c0eaa90671/fleetbench/swissmap/hot_swissmap_benchmark.cc (L48))
has a `const uint32_t key` is passed to to the lookup of a hashtable.
With the `key` marked `const`, LLVM hoists part of the lookup
calculation outside of the loop.

With the `const` removed, this hoisting does not occur.

Co-authored-by: Dominic Hamon <dominichamon@users.noreply.github.com>
Co-authored-by: dominic <510002+dmah42@users.noreply.github.com>
2023-02-06 15:50:37 +00:00
dominic 94083ca441
remove best effort support for ubuntu 18.04 (#1537)
* remove deprecated ubuntu-18.04 target

* update docs

* force an apt update for perfcounters
2023-02-06 15:37:26 +00:00
dominic 1318865305
try disabling liquid for jekyll to fix curly braces (#1536)
* try disabling liquid for jekyll to fix curly braces

* do it properly with commented out tags
2023-02-06 14:01:16 +00:00
Nicholas Junge 80a3c5e4d9
Switch bindings implementation to `nanobind` (#1526)
* End support for Python 3.7, update cibuildwheel and publish actions

Removes Python 3.7 from the support matrix, since it does not support
PEP590 vectorcalls.

Bumps the `cibuildwheel` and `pypa-publish` actions to their latest
available versions respectively.

* Add nanobind to the Bazel dependencies, add a BUILD file

The build file builds nanobind as a static `cc_library`. Currently,
the git SHA points to HEAD, since some necessary features have not
been included in a release yet.

* Delete pybind11 BUILD file

* Switch bindings implementation to nanobind

Switches over the binding tool to `nanobind` from `pybind11`. Most
changes in the build setup itself were drop-in replacements of existing
code changed to nanobind names, no new concepts needed to be
implemented.

Sets the minimum required macOS to 10.14 for full C++17 support. Also,
to avoid ambiguities in Bazel, build for macOS 11 on Mac ARM64.

* Use Bazel select for linker options

Guards against unknown linker option errors by selecting required
linker options for nanobind only on macOS, where they are relevant.

Other changes:
* Bump cibuildwheel action to v2.12.0
* Bump Bazel for aarch64 linux wheels to 6.0.0
* Remove C++17 flag from build files since it is present in setup.py `bazel build` command
* Bump nanobind commit to current HEAD (TBD: Bump to next stable release)

* Unbreak Windows builds of nanobind-based bindings

Guards compiler options behind a new `select` macro choosing between
MSVC and not MSVC.

Other changes:
* Inject the proper C++17 standard cxxopt in the `setup.py` build
command.
* Bump nanobind to current HEAD.
* Make `macos` a benchmark-wide condition, with public visibility to
allow its use in the nanobind BUILD file.

* Fall back to `nb::implicitly_convertible` for Counter construction

Since `benchmark::Counter` only has a constructor for `double`,
the nanobind `nb::init_implicit` template cannot be used. Therefore,
to support implicit construction from ints, we fall back to the
`nb::implicitly_convertible` template instead.
2023-02-06 13:07:17 +00:00
Nicholas Junge f59d021ebc
Modernize setup.py, extend Python bindings CI (#1535)
distutils is deprecated and will be removed in Python 3.12, so this
commit modernizes the Python bindings `setup.py` file in order to
future-proof the code.

On top of this, type hints were added for all of the convenience
functions to make static type checking adoption easier in the future,
if desired.

A context manager was added to temporarily write the Python include
path to the Bazel WORKSPACE file - but unlike previously, the
WORKSPACE file is reverted to its previous state after the build to not
produce changes on every rebuild.

Lastly, the Python bindings test matrix was extended to all major
platforms to create a more complete picture of the current state of
the bindings, especially with regards to upcoming wheel builds.
2023-02-03 09:47:02 +00:00
Vy Nguyen 5e78bedfb0
Add quick instructions on how to enable sans checks (#1529)
Co-authored-by: dominic hamon <510002+dmah42@users.noreply.github.com>
2023-01-17 14:18:57 +00:00
SunBlack cfbc94960f
Fix Clang-Tidy warnings readability-else-after-return (#1528) 2023-01-16 12:28:48 +00:00
Vy Nguyen a3235d7b69
Include the benchmark's family-name in State (#1511)
* Include the benchmark's family-name in State

For compat with internal library, where State::name() returns the benchmark's family name.

* added missing files from prev commit

* fix field-init order error

* added test
2023-01-10 16:48:17 +00:00
SunBlack fe65457e80
Fix typos found by codespell (#1519) 2023-01-10 12:25:32 +00:00
SunBlack 37faf6f975
Fix Clang-Tidy warnings related to modernize-use-override (#1523) 2023-01-09 17:52:18 +00:00
Yury Fedorov 62edc4fb00
Bug fix variable 'actual_iterations' set but not used (#1517)
* Bug fix variable 'actual_iterations' set but not used

Compiling the project in clang 15 without -Wno-unused-but-set-variable flag the following error is generated:

benchmark-src/test/options_test.cc:70:10: error: variable 'actual_iterations' set but not used [-Werror,-Wunused-but-set-variable]
  size_t actual_iterations = 0;
         ^

* Adjust according formatting of `clang-format`

Co-authored-by: dominic hamon <510002+dmah42@users.noreply.github.com>
2022-12-19 14:03:11 +00:00
Dominic Hamon fe5a386b40 add more docs to index 2022-12-19 12:35:00 +00:00