Commit Graph

1574 Commits

Author SHA1 Message Date
Nicholas Junge 754ef08ab9
Upgrade core bazel dependencies (#1711)
Bumps `rules_foreign_cc` to v0.10.1 (October 2023), `bazel_skylib` to
v1.5.0 (November 2023), `rules_python` to v0.27.1 (December 2023).

Also syncs GoogleTest to v1.12.1 (the last C++11 supporting version) to
be the same as in MODULE.bazel.

Since the latest `rules_python` changed its setup calling convention,
that is updated also in the WORKSPACE file.
2023-12-07 15:00:43 +00:00
Nicholas Junge e2c13db77a
Fix editable install by unsetting `build_ext.copy_extensions_to_source` (#1710)
This method was the culprit for the recent editable install breakage,
since it just tries to copy the generated extension file without checking
its existence.

Since the `BazelExtension` uses a non-standard location to store the
build artifacts, calling the copy method fails the build since the
extension is not found in the expected location.

But, since we already copy the file into the source tree as part of the
`BazelExtension.bazel_build` method, it's fine - the extension appears
in the right place, and the egg info is generated correctly as well.

This method also does not affect the general install, so it solves the
editable problem without regressing the fixed install.

Co-authored-by: dominic <510002+dmah42@users.noreply.github.com>
2023-12-07 12:35:20 +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
Nicholas Junge 68689bf966
Fix `pre-commit` GitHub Actions job (#1708)
For some reason, editable pip installs are now broken, which means that
they will break the pre-commit workflow due to the `pip install -e .`
instruction.

Since the normal install is unaffected, we can just drop the `-e` switch.
It does not matter which mode is used, since the environment is only
used for linting.
2023-12-07 09:41:34 +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
Roman Lebedev c8ef1ee99e
[CI] Try to fix sanitizer builds by pinning the LLVM revision (#1703) 2023-11-23 08:45:02 +00:00
illbegood 4a2e34ba73
Fix CMakeLists.txt for perf_counters_test (#1701) 2023-11-16 09:55:59 +00:00
Anjan Roy 93a96a26a6
Add missing `\n` character at end of error log string (#1700)
Closes https://github.com/google/benchmark/issues/1699

Signed-off-by: Anjan Roy <hello@itzmeanjan.in>
2023-11-13 17:39:32 +00:00
Nicholas Junge 159eb2d0ff
Switch out black for ruff format (#1698)
Saves one pre-commit hook, some pyproject.toml configuration,
and provides much better performance with almost identical behavior.

Co-authored-by: dominic <510002+dmah42@users.noreply.github.com>
2023-11-10 10:40:31 +00:00
Tiago Freire a543fcd410
Fixed compiler warnings (#1697)
* fixed warnings
used proper math functions

* ran clang format

* used a more up-to-date clang-format

* space twedling

* reveretd CMakeLists.txt
2023-11-10 10:09:50 +00: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
Nicholas Junge 3623765dd3
Add `setuptools_scm` for dynamic zero-config Python versioning (#1690)
* Add `setuptools_scm` for dynamic zero-config Python versioning

This removes the need for manually bumping versions in the Python
bindings.

For the wheel uploads, the correct semver version is inferred in the case
of tagged commits, which is exactly the case in GitHub CI.

The docs were updated to reflect the changes in the release workflow.

* Add separate version variable and module, use PEP484-compliant exports

This is the best practice mentioned in the `setuptools_scm` docs, see
https://setuptools-scm.readthedocs.io/en/latest/usage/#version-at-runtime.
2023-11-01 09:48:01 +00:00
Nicholas Junge bce46fb413
Drop isort hook for ruff builtin import sorting (#1689)
This behaves the same, and saves a pre-commit step. ruff just needs an
additional package location hint to correctly map first-part packages
(in this case, `google_benchmark`).

This revealed a misformat in the `google_benchmark.__init__`, which is
now fixed.
2023-10-31 10:05:37 +00:00
Nicholas Junge b93f5a5929
Add pre-commit config and GitHub Actions job (#1688)
* Add pre-commit config and GitHub Actions job

Contains the following hooks:
* buildifier - for formatting and linting Bazel files.
* mypy, ruff, isort, black - for Python typechecking, import hygiene,
static analysis, and formatting.

The pylint CI job was changed to be a pre-commit CI job, where pre-commit
is bootstrapped via Python.

Pylint is currently no longer part of the
code checks, but can be re-added if requested. The reason to drop was
that it does not play nicely with pre-commit, and lots of its
functionality and responsibilities are actually covered in ruff.

* Add dev extra to pyproject.toml for development installs

* Clarify that pre-commit contains only Python and Bazel hooks

* Add one-line docstrings to Bazel modules

* Apply buildifier pre-commit fixes to Bazel files

* Apply pre-commit fixes to Python files

* Supply --profile=black to isort to prevent conflicts

* Fix nanobind build file formatting

* Add tooling configs to `pyproject.toml`

In particular, set line length 80 for all Python files.

* Reformat all Python files to line length 80, fix return type annotations

Also ignores the `tools/compare.py` and `tools/gbench/report.py` files
for mypy, since they emit a barrage of errors which we can deal with
later. The errors are mostly related to dynamic classmethod definition.
2023-10-30 15:35:37 +00:00
Nicholas Junge b219e18b91
[bindings] Add LTO builds on Windows+MSVC (#1687)
* Add LTO builds on Windows+MSVC

Gates the MSVC switches behind an `@bazel_skylib:selects` statement.

This is a first experiment from best guesses and studying the MSVC docs.

* Fix misleading inline comment
2023-10-27 12:49:43 +01:00
Nicholas Junge 698d1dc8c3
Reapply size optimizations for clang & MSVC, LTO for Mac+Linux (#1685)
* Reapply size optimization for clang, equivalent options for MSVC

Working towards cross-platform optimal nanobind building configurations.

* Add LTO back to non-Windows builds

The Windows case (the option name is "/GL") is more complicated, since
there, the compiler options also need to be passed to the linker if LTO
is enabled.

Since we are gating the linker options on platform at the moment instead
of compiler, we need to implement a Bazel boolean flag for the case
"Platform == MacOS && Compiler == AnyOf(gcc, clang)".
2023-10-25 12:12:18 +01:00
Nicholas Junge e45585a4b8
Change nanobind linkage to response file approach on macOS (#1638)
* Change nanobind linkage to response file approach

This change needs https://github.com/bazelbuild/bazel/pull/18952 to be
merged first. Fixes macOS linkage of GBM's nanobind bindings on macOS by
supplying a linker response file instead of `-undefined dynamic_lookup`.

The latter has since been deprecated on macOS.

* Fix bazel_skylib checksum, bump skylib version in MODULE.bazel

* Bump Bazel to version 6.4.0 for linker response file support
2023-10-24 13:04:12 +01:00
Nicholas Junge 5893034e46
Add Python 3.12 support (#1676)
* Add Python 3.12 support tag

* Bump nanobind to latest stable v1.6.2 tag

* Add PyPI trusted publishing to GitHub workflow, add Python 3.12 wheel builds

Trusted publishing has been available since v1.8.0 of the pypa-publish
action. It enables password-less authentication and wheel uploads from
the wheel upload job.

`cibuildwheel` was bumped to v2.16.2 to allow Python 3.12 wheel builds.

More info on trusted publishing:
https://github.com/marketplace/actions/pypi-publish#trusted-publishing

The Windows distribution was reverted to `latest` in the OS matrix,
since the discovery problem of MSVC was fixed in a Bazel patch release.

* Bump nanobind to stable v1.7.0 tag
2023-10-23 13:04:39 +01:00
dominic 6a16cee366
Add no-unititialized to tests (#1683) 2023-10-23 08:54:08 +00:00
Vy Nguyen 7495f83e2a
Set -Wno-unused-variable for tests (#1682)
We  used assert() a lot in tests and that can cause build breakages in some of the opt builds (since assert() are removed)

it's not practical to sprinkle "(void)" everywhere so I think setting this warning option is the best option for now.
2023-10-20 12:51:32 +00:00
Andreas Abel f30c99a7c8
Increase the kMaxIterations limit (#1668)
* Increase the kMaxIterations limit

This fixes #1663. Note that as a result of this change, the columns in the console output can become misaligned if the actual iteration count is too high. This will be dealt with in a separate commit.

* Fix failing test on Windows

* Fix formatting

---------

Co-authored-by: dominic <510002+dmah42@users.noreply.github.com>
2023-10-17 17:13:59 +01:00
Dominic Hamon 365bf7602b fix format in src/sysinfo 2023-10-17 16:50:22 +01:00
dominic dc9b229b78
add name to clang format job 2023-10-17 16:47:29 +01:00
Ming Zero ea3c3f983b
Fix building on MinGW: default `WINVER` is too old (#1681)
MinGW defaults `WINVER` to something very old,
while benchmark requires features gated by `WINVER = 0x0600`,
so manually set update to that.
2023-10-16 18:19:17 +03:00
mosfet80 682153afda
Update bazel.yml (#1671)
Updated actions/checkout@v4

Co-authored-by: dominic <510002+dmah42@users.noreply.github.com>
2023-10-13 10:59:20 -04:00
dominic ca8d0f7b61
correct cli param in docs 2023-10-08 11:08:46 +01:00
Andreas Abel 7736df0304
Make json and csv output consistent. (#1662)
* Make json and csv output consistent.

Currently, the --benchmark_format=csv option does not output the correct value for the cv statistics. Also, the json output should not contain a time unit for the cv statistics.

* fix formatting

* undo json change

---------

Co-authored-by: dominic <510002+dmah42@users.noreply.github.com>
2023-09-26 13:43:23 +01:00
Mészáros Gergely c9106a79fa
Audit MSVC references in cmake files to consider clang++ (#1669)
There are three major compilers on Windows targeting the MSVC ABI (i.e.
linking with microsofts STL etc.):
  - `MSVC`
  - `clang-cl` aka clang with the MSVC compatible CLI
  - `clang++` aka clang with gcc compatible CLI

The cmake variable `MSVC` is only set for the first two as it defined in
terms of the CLI interface provided:

> Set to true when the compiler is some version of Microsoft Visual
> C++ or another compiler simulating the Visual C++ cl command-line syntax.

(from cmake docs)

For many of the tests in the library its the ABI that matters not the
cmdline, so check `CMAKE_CXX_SIMULATE_ID` too, if it is `MSVC` the
current compiler is targeting the MSVC ABI. This handles `clang++`
2023-09-26 12:31:24 +01:00
Dominic Hamon 344117638c bump version to 1.8.3 2023-08-31 13:16:50 +01:00
Dominic Hamon db3e000c1e Merge branch 'jmr-stat-median' 2023-08-25 09:59:02 +01:00
Dominic Hamon 78220d6f0d tweak comment wording 2023-08-25 09:58:30 +01:00
dominic 9f254bddf0
Merge branch 'main' into stat-median 2023-08-24 17:50:56 +01:00
Jesse Rosenstock 6dd50bb606 StatisticsMedian: Fix bug
Previously, this could return the wrong result when there
was an even number of elements.

There were two `nth_element` calls.  The second call could
change elements in `[center2, end])`, which was where
`center` pointed.  Therefore, `*center` sometimes had the
wrong value after the second `nth_element` call.

Rewrite to use `max_element` instead of the second call to
`nth_element`.  This avoids modifying the vector.
2023-08-24 16:05:09 +02:00
Jesse Rosenstock dfc8a92abc
test: Use gtest_main only when needed (#1657)
* test: Use gtest_main only when needed

There are two types of tests.  `*_gtest.cc` files use `gtest` and
`gtest_main`.  `*_test.cc` files define their own main.

Only depend on `gtest`/`gtest_main` when needed.  This is similar
to what `CMakeLists.txt` does.

* comment-only: gunit => gtest

* Fix typo
2023-08-24 13:43:50 +01:00
Jesse Rosenstock 9c65aebb26
perf_counters: Initialize once only when needed (#1656)
* perf_counters: Initialize once only when needed

This works around some performance problems running Android under QEMU.
Calling `pfm_initialize` was very slow, and was called during dynamic
initialization (before `main` or when loaded as a shared library).
This happened whenever benchmark was linked, even if no benchmarks
were run.

Instead, call `pfm_initialize` at most once, and only when one of:
1. `PerfCounters::Initialize` is called
2. `PerfCounters::Create` is called with a non-empty counter list
3. `PerfCounters::IsCounterSupported` is called

The return value of the first `pfm_initialize()` is saved and
returned from all subsequent `PerfCounters::Initialize` calls.

* perf_counters: Make success var const

* InitLibPfmOnce: Inline function
2023-08-24 10:04:09 +01:00
Jesse Rosenstock e73915667c
State: Initialize counters with kAvgIteration in constructor (#1652)
* State: Initialize counters with kAvgIteration in constructor

Previously, `counters` was updated in `PauseTiming()` with
`counters[name] += Counter(measurement, kAvgIteration)`.

The first `counters[name]` call inserts a counter with no flags.

There is no `operator+=` for `Counter`, so the insertion is done
by converting the `Counter` to a `double`, then constructing a
`Counter` to insert from the `double`, which drops the flags.

Pre-insert the `Counter` with the correct flags, then only
update `Counter::value`.

Introduced in 1c64a36 ([perf-counters] Fix pause/resume (#1643)).

* perf_counters_test.cc: Don't divide by iterations

Perf counters are now divided by iterations, so dividing again
in the test is wrong.

* State: Fix shadowed param error

* benchmark.cc: Fix clang-tidy error

---------

Co-authored-by: dominic <510002+dmah42@users.noreply.github.com>
2023-08-21 15:35:42 +01:00
Jesse Rosenstock e441a8cb11
perf-counters: Make tests pass on Android (#1653)
* perf_counters_gtest: Make test pass on Android

Tested on Pixel 3 and Pixel 6.  Reduce test to the intersection of
what passes on all platforms.

Pixel 6 doesn't support BRANCHES, and only supports two perf
counters.


---------

Co-authored-by: dominic <510002+dmah42@users.noreply.github.com>
2023-08-21 15:04:50 +01:00
dominic fe1ca332a8
add logo to github pages 2023-08-21 14:31:58 +01:00
Dominic Hamon 9ba2af8d52 add black icon 2023-08-21 14:29:55 +01:00
dominic 87169dd3f5
remove logo from generated docs 2023-08-21 14:25:30 +01:00
dominic 83939d0bd4
remove icon from main README 2023-08-21 14:24:38 +01:00
dominic 05ed7ba2a2
update logo path 2023-08-21 14:21:47 +01:00
Dominic Hamon 72938cc1c5 adding a logo to the docs 2023-08-21 14:21:07 +01:00
Jesse Rosenstock 885e9f71d6
benchmark.cc: Fix benchmarks_with_threads condition (#1651)
Change condition for `benchmarks_with_threads` from `benchmark.threads() > 0` to `> 1`.  `threads()` appears to always be `>= 1`.

Introduced in fbc6efa (Refactoring of PerfCounters infrastructure (#1559))
2023-08-17 15:41:17 +01:00
Jesse Rosenstock aa59d40f88
sysinfo.cc: Call getloadavg for Android API >= 29 (#1) (#1649)
Support for `getloadavg` was added in API level 29.
2023-08-14 17:02:42 +01:00
Mircea Trofin 1c64a36c5b
[perf-counters] Fix pause/resume (#1643)
* [perf-counters] Fix pause/resume

Using `state.PauseTiming() / state.ResumeTiming()` was broken.

Thanks [@virajbshah] for the the repro testcase.

* ran clang-format over the whole perf_counters_test.cc

* Remove check that perf counters are 0 on `Pause`, since `Pause`/`Resume`
sequences would cause a non-0 counter value

* both upper and lower bound for the with/without resume counters

---------

Co-authored-by: dominic <510002+dmah42@users.noreply.github.com>
2023-08-11 12:46:36 +01:00
Devansh Varshney (देवांश वार्ष्णेय) cbecc8ffc7
fix: added benchmark_counters_tabular for file (#1645)
* fix: added benchmark_counters_tabular for file

* fix: only checking the counters_tabular flag
2023-08-11 10:59:53 +01:00
Ioanna-Maria Panagou 14961f1cb6
Fix IntelLLVM compiler error (#1644)
* add -fno-finite-math-only for IntelLLVM
2023-08-10 10:33:10 +01:00
देवांश वार्ष्णेय 02a354f3f3
bug: Inconsistent suffixes console reporter 1009 (#1631)
* removed appendHumanReadable as it was not used anywhere

---------

Co-authored-by: dominic <510002+dmah42@users.noreply.github.com>
2023-08-01 08:47:09 +01:00
Andy Christiansen 6e80474e62
Mark internal deps as dev_depenencies so that downstream modules don't require those. (#1640)
Co-authored-by: Andy Christiansen <achristiansen@google.com>
Co-authored-by: dominic <510002+dmah42@users.noreply.github.com>
2023-07-31 17:23:27 +01:00