Commit Graph

1509 Commits

Author SHA1 Message Date
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
Tiago Freire
654d8d6cf3
Fixed LTO issue on no discard variable (#1761)
Improve `UseCharPointer()` (thus, `DoNotOptimize()`) under MSVC LTO,
make it actually escape the pointer and prevent it from being optimized away.
2024-03-06 15:50:45 +03: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
7f7c96a264
sysinfo.cc: Always abort on GetNumCPUs failure (#1756)
Defines a wrapper function, CheckNumCPUs, which enforces that GetNumCPUs
never returns fewer than one CPU.  There is no reasonable way to
continue if we are unable to identify the number of CPUs.

Signed-off-by: Sam James <sam@gentoo.org>
2024-02-14 20:19:46 +03: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
Matthias Liedtke
b7ad5e0497
fix typo in GetBenchmarkVersion() (#1755) 2024-02-12 16:56:58 +00:00
Roman Lebedev
b04cec1bf9
Deflake CI (#1751)
* `complexity_test`: deflake, same as https://github.com/google/benchmark/issues/272

As it can be seen in e.g. https://github.com/google/benchmark/actions/runs/7711328637/job/21016492361
We may get `65: BM_Complexity_O1_BigO                           0.00 N^2        0.00 N^2  `

* `user_counters_tabular_test`: deflake

We were still getting zero times there. Perhaps this is better?
2024-02-02 18:39:46 +03: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
dominic
30a37e1b0b
set library version in bazel (#1746)
* set library version in bazel
2024-01-29 13:48:04 +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
Dominic Hamon
8e2d258644 ignore new bzlmod lock file 2024-01-29 13:06:57 +00:00
Dominic Hamon
faef450eb9 changes to run bazel migration scripts
part of #1743
2024-01-29 13:02:29 +00:00
Nicholas Junge
4682db08bc
Bump pre-commit dependencies (#1740)
Also fix a mypy error in `tools.gbench.util` - the condition behaves the
same as before, but in the new mypy version, the old condition results
in an unreachable code error for the final `return False` statement.

This is most likely a bug in mypy's reachability analysis, but the fix
is easy enough here to circumvent it.
2024-01-18 13:35:57 +00:00
Aleksey
3d293cd67a
Fix C-style typecasting in QNX-specific code (#1739)
C-style typecasting breaks the build due to `-Werror=old-style-cast` which should remain in place.
2024-01-16 12:28:04 +00:00
Roman Lebedev
ea71a14891
Docs: reducing_variance.md: proofreading, fix typos (#1736) 2024-01-10 09:37:39 +00:00
Ananta Bastola
882f6f5ae0
fix(cmakelists.txt): enforce CMake to find PFM or fail when BENCHMARK_ENABLE_LIBPFM is ON (#1705)
Fixes #1702
2024-01-09 18:34:42 +03:00
Benny Tordrup
54e4327190
Issue 1734: Streams not flushed if not running actual benchmarks (#1735)
Consistently flush Out and Err streams, otherwise they might not get flushed
and the output lost when using custom streams.

Fixes #1734.
2024-01-09 17:59:10 +03:00
Roman Lebedev
96d820f73f
tools/compare: don't actually discard valid (but zero) pvalue (#1733)
* tools/compare: when dumping json, pretty-print it

It's rather completely non-human-readable otherwise.
I can't imagine the filesize really matters,
and if it does, it should just be compressed later on.

* tools/compare: add failing test

* tools/compare: don't actually discard valid (but zero) `pvalue`

So, this is embarressing. For a very large number of repetitions,
we can end up with pvalue of a true zero, and it obviously compares false,
and we treat it as-if we failed to compute it...
2024-01-08 09:57:00 +00:00
Benny Tordrup
e61e332df9
Issue1731 created console does not receive output (#1732)
* Instead of directly comparing std::cout and GetOutputStream(), the underlying buffers are retreived via rdbuf(), and then compared.

* Instead of fflush(stdout), call out.flush().
Use out << FormatString() instead of vprintf

---------

Co-authored-by: dominic <510002+dmah42@users.noreply.github.com>
2024-01-05 14:08:28 +00:00
Dominic Hamon
4575fc415f Merge branch 'aqrose-aidi-sdk-team-main' 2024-01-05 10:41:54 +00:00
FantasqueX
a6b78ef168
Change Fixture to use non-const SetUp and TearDown in example (#1723)
Const SetUp and TearDown were deprecated in https://github.com/google/benchmark/pull/285

Co-authored-by: dominic <510002+dmah42@users.noreply.github.com>
2024-01-05 10:35:20 +00:00
Li-Yu Yu
07c98d5a44
Avoid leaking LFS flags to reverse dependencies (#1730)
Follow up of #1725.

`defines` propagates to reverse dependencies, while `local_defines`
don't. If we use `defines` then there's risk of ODR violation:

Suppose a user have a cc_library foo that depends on bar and benchmark:

    cc_library(name = "foo", deps = [":bar", "@com_github_google_benchmark//:benchmark"])

And bar has a class that has LFS-dependant ABI:

    cc_library(name = "foo")

    class Bar {
        off_t member;
    };

Bar would be compiled without LFS, but linked to foo when assuming LFS is enabled.

So we limit LFS to within the library only. benchmark does not have
LFS dependant public ABIs so it should be fine.
2024-01-05 10:27:12 +00:00
dhmemi
e0ec670d20 style: re-format BUILD file with buildifier. 2024-01-05 11:23:23 +08:00
Abhina Sree
e3824e7503
fix per-thread timing error on z/OS (#1719)
Co-authored-by: dominic <510002+dmah42@users.noreply.github.com>
2024-01-04 11:07:01 +00:00
Tommy Chiang
c213e41eb9
Enable Large-file Support (#1726)
* Enable Large-file Support

This should fix https://github.com/google/benchmark/issues/1725

* Use whitespaces instead of tab in BUILD.bazel

---------

Co-authored-by: dominic <510002+dmah42@users.noreply.github.com>
2024-01-04 10:50:33 +00:00
aurel32
99bdb2127d
CycleClock: use RDTIME instead of RDCYCLE on RISC-V (#1727)
Starting with Linux 6.6 [1], RDCYCLE is a privileged instruction on
RISC-V and can't be used directly from userland. There is a sysctl
option to change that as a transition period, but it will eventually
disappear.

Use RDTIME instead, which while less accurate has the advantage of being
synchronized between CPU (and thus monotonic) and of constant frequency.

[1] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=cc4c07c89aada16229084eeb93895c95b7eabaa3

Co-authored-by: dominic <510002+dmah42@users.noreply.github.com>
2024-01-04 09:16:40 +00:00
hamptonm1
e523e454f2
Update perf_counters_gtest.cc (#1728) 2024-01-04 09:11:07 +00:00
Afanasyev Ivan
2d2e07e3c5
Fix division by zero for low frequency timers for CV statistics (#1724) 2024-01-03 12:40:59 +00:00
dhmemi
3028899d61 fix: fail to import gbench in bazel and python3.12 2023-12-22 10:24:23 +08:00
Abhina Sree
7b52bf7346
define HOST_NAME_MAX for z/oS (#1717) 2023-12-20 17:18:37 +00:00
IS
6b7e86c5c8
Fix mis-matching argument in closing tag for cmake macro (#1714) (#1715)
Co-authored-by: Iakov Sergeev <yahontu@gmail.com>
2023-12-20 09:54:55 +00:00
Nicholas Junge
9a0422eb23
Check out repo at depth 0 for Python tests, bump Python and PyPI actions (#1713)
The reason for this is that `setuptools-scm` installs a version relative
to the last release tag - if no tag is found, the default version is taken
to be v0.1.0. This was the case in GitHub Actions, where only the PR
branch is checked out.

Also unpins build system requirements in the `pyproject.toml`.

The sdist build system was changed to `build` from `python setup.py sdist`
for forward compatibility - `build` is superior in every way, and the
advertised solution by both cibuildwheel and PyPA itself.

Bump `actions/setup-python` to v5, `pypa/gh-action-pypi-publish` to v1.8.11,
and `docker/setup-qemu-action` to v3.
2023-12-19 14:13:08 +00:00
Nicholas Junge
c2de526130
Run pre-commit autoupdate, fix stale pyproject.toml comments (#1712)
* Run `pre-commit autoupdate`, fix stale pyproject.toml comments

* Set `--enable_bzlmod=false` for the moment

Until the newer nanobind tags are pushed to the BCR, it's best to disable
bzlmod for the bindings, because the Python CI breaks due to Bazel 7
enabling bzlmod by default.

* Remove E203 ignore, add linebreaks to semantically group ruff options
2023-12-13 14:26:15 +00:00
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