Commit graph

1298 commits

Author SHA1 Message Date
Dominic Hamon b7afda2cd2
Revert "Add possibility to ask for libbenchmark version number (#1004) (#1403)" (#1417)
This reverts commit efadf67a12.
2022-06-20 17:52:03 +01:00
Dominic Hamon af7de865eb
Clarify that the cpu frequency is not used for benchmark timings. (#1414)
* Clarify that the cpu frequency is not used for benchmark timings.

Fixes #1310

* fix format (clang-format missed this...)

* oops
2022-06-20 11:22:57 +01:00
Alexander Popov 8545dfb3ea
Fix DoNotOptimize() GCC copy overhead (#1340) (#1410)
* Fix DoNotOptimize() GCC copy overhead (#1340)

The issue is that GCC DoNotOptimize() does a full copy of an argument
if it's not a pointer and it slows down a benchmark. If an argument is big
enough there is a memcpy() call for copying the argument. An argument
object can be a big object so DoNotOptimize() could add sufficient
overhead and affects benchmark results.

The cause is in GCC behavior with asm volatile constraints. Looks like GCC
trying to use r(register) constraint for all cases despite object size.
See: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105519

The solution is the split DoNotOptimize() in two cases - value fits
in register and value doesn't fit in register. And use case specific
asm constraint. std::is_trivially_copyable trait is needed because
"+r" constraint doesn't work with non trivial copyable objects.

- Fix requires support C++11 feature std::is_trivially_copyable from GCC
  compiler. The feature has been supported since GCC 5
- Fallback for GCC version < 5 still exists but it uses "m" constraint
  which means a little bit more overhead in some cases
- Add assembly tests for issued cases

Fixes #1340

* Add supported compiler versions info for assembly tests

- Assembly tests are inherently non-portable. So explicitly add GCC
  and Clang versions required for reliable tests passed
- Write a warning message if the current compiler version isn't supported
2022-06-20 10:12:58 +01:00
Matthias Donaubauer efadf67a12
Add possibility to ask for libbenchmark version number (#1004) (#1403)
* Add possibility to ask for libbenchmark version number (#1004)

Add a header which holds the current major, minor, and
patch number of the library. The header is auto generated
by CMake.

* Do not generate unused functions (#1004)

* Add support for version number in bazel (#1004)

* Fix clang format #1004

* Fix more clang format problems (#1004)

* Use git version feature of cmake to determine current lib version

* Rename version_config header to version

* Bake git version into bazel build

* Use same input config header as in cmake for version.h

* Adapt the releasing.md to include versioning in bazel
2022-06-20 09:45:50 +01:00
Dominic Hamon 2365c4a603
add multiple OSes to bazel workflow (#1412)
* add multiple OSes to bazel workflow

* correct indent

* only set copts when they're supported by the OS

* os check should work

* pull out cxx03_test for per-platform stuff

* attempt to fix windows test output
2022-06-13 17:45:20 +01:00
Dominic Hamon 920fa14898 fix some build warnings on type conversions 2022-06-08 10:32:20 +01:00
Dominic Hamon 108ca84820 fix typo in comment 2022-06-07 14:15:03 +01:00
Matthdonau 6d50251d8e
Report large numbers in scientific notation in console reporter (#1303) (#1402)
Report all time numbers > 10 digits in scientific notation with
4 decimal places. This is necessary since only 10 digits
are currently reserved for the time columns (Time and CPU).
If exceeding 10 digits the output isnt properly aligned anymore.
2022-05-27 09:29:53 +01:00
Matthdonau 7eb8c0fe45
Introduce warmup phase to BenchmarkRunner (#1130) (#1399)
* Introduce warmup phase to BenchmarkRunner (#1130)

In order to account for caching effects in user
benchmarks introduce a new command line option
"--benchmark_min_warmup_time"
which allows to specify an amount of time for
which the benchmark should be run before results
are meaningful.

* Adapt review suggestions regarding introduction of warmup phase (#1130)

* Fix BM_CHECK call in MinWarmUpTime (#1130)

* Fix comment on requirements of MinWarmUpTime (#1130)

* Add basic description of warmup phase mechanism to user guide (#1130)
2022-05-23 13:50:17 +01:00
Zi Xuan Wu (Zeson) 6c46c9f593
Add support to get clock for new architecture CSKY (#1400)
it's like what loongarch does to get cycle clock for CSKY by gettimeofday function.
2022-05-23 11:47:58 +01:00
Matthdonau 37be1e8252
Add option to get the verbosity provided by commandline flag -v (#1330) (#1397)
* Add option to get the verbosity provided by commandline flag -v (#1330)

* replace assert with test failure

asserts are stripped out in non debug builds, and we run tests in non-debug CI bots.

* clang-format my own tweak

Co-authored-by: Dominic Hamon <dominichamon@users.noreply.github.com>
2022-05-17 17:59:36 +01:00
cui fliter aecbdbff4f
fix some typos (#1393)
Signed-off-by: cuishuang <imcusg@gmail.com>
2022-05-11 09:03:20 +01:00
Nicholas Junge bc4639c154
Add installation and build instructions for Python bindings (#1392)
This commit adds a small section on how to install and build Python
bindings wheels to the docs, as well as a link to it from the main readme.

Notes were added that clearly state availability of Python wheels based
on Python version and OS/architecture combinations.

For the guide to build a wheel from source, the best practice of
creating a virtual environment and activating it before build was
detailed. Also, a note on the required installation of Bazel was added,
with a link to the official docs on installation.
2022-05-10 13:16:00 +01:00
Dominic Hamon 8d86026c67
Enable -Wconversion (#1390)
Requires some casts here and there, but nothing unreasonable.

Fixes #1268
2022-05-01 19:56:30 +01:00
Dominic Hamon b0d5adfacd
Add benchmark labels to the output of the comparison tool (#1388)
Fixes #1294
2022-05-01 15:04:39 +01:00
Dominic Hamon a162a38ca0
Filter out benchmarks that start with "DISABLED_" (#1387)
* Filter out benchmarks that start with "DISABLED_"

This could be slightly more elegant, in that the registration and the
benchmark definition names have to change.  Ideally, we'd still register
without the DISABLED_ prefix and it would all "just work".

Fixes #1365

* add some documentation
2022-05-01 10:41:34 +01:00
Nicholas Junge dc901ff909
Fix wheel job name for PyPI uploads (#1384)
Previously, with the unrolled job matrix, all jobs had to be listed individually in the `needs` section of the PyPI upload job. But as the wheel build job was reimplemented as a job matrix now, with a
single build job name `build_wheels`, we need to adjust the name in the PyPI upload job as well here to avoid errors.
2022-04-11 09:17:54 +01:00
Nicholas Junge 6f75bb5273
Shut down Bazel gracefully and revert wheel build strategy to job matrix (#1383)
This commit adds a `bazel shutdown` command to the setuptools BazelExtension. This has the effect that wheel builds shut down the Bazel server and terminate gracefully after the build, something
that was previously an issue on Windows builds.

Since the windows-specific `--no-clean` flag option to `pip wheel` becomes unnecessary due to this change, this change has the side-effect that GitHub Actions wheel builds via `cibuildwheel` can now
be written as a compact job matrix again, which leads to a lot of deduplicated code in the corresponding workflow file.

Lastly, some GitHub-provided actions (checkout, setup-python, upload/download-artifact) were bumped to the latest v3 version.
2022-04-08 15:00:46 +01:00
Dominic Hamon 74ae567294
Small optimization to counter map management (#1382)
* Small optimization to counter map management

Avoids an unnecessary lookup.

* formatting
2022-04-07 14:37:22 +01:00
Dominic Hamon 3eac3b60d2
getting sysinfo in line with Google style (#1381)
* getting sysinfo in line with Google style

* format tweak

* fixing osx compile errors

* more style tweaks
2022-04-07 10:50:52 +01:00
Brad Messer 60b16f11a3
Promote inclusive language. (#1360) 2022-03-18 15:59:31 +00:00
Vy Nguyen a480a088fe
[nfc] Reformat doc-string in generate_export_header (#1376)
This was previously not compliant with Buildifier checker
2022-03-17 18:31:36 +00:00
Paul Wankadia 808571a52f
Fix Bazel build breakage caused by commit 6a894bd. (#1374) 2022-03-17 09:29:50 +00:00
Paul Wankadia 6a894bd555
Build //:benchmark as a static library only. (#1373)
If someone or something ever needs the dynamic library as a Bazel build
artifact, we can figure that out for them then, but right now, there is
no strong reason to be wrangling various `export.h`-controlling macros.

Fixes #1372.
2022-03-17 08:47:45 +00:00
Dominic Hamon 5704cd4c8c
add note about wheels action to releasing docs 2022-03-15 15:11:43 +00:00
Nicholas Junge 3eab98544f
Change artifact download name to dist to match upload name (#1371) 2022-03-15 12:56:01 +00:00
Nicholas Junge 7d6f1534e9
Remove conditional trigger from PyPI upload job (#1370) 2022-03-15 11:06:30 +00:00
Nicholas Junge 9a71e5d748
Add BENCHMARK_STATIC_DEFINE to the Python bindings' cc_binary local defines. (#1369)
This commit fixes the previous breakage in Python wheel builds for Windows by adding a `local_defines` field to the `cc_binary` generated in the process of the Python bindings builds. This define is being
picked up by the auto-generated export header `benchmark_export.h`, unsetting the benchmark export macro.
Furthermore, the `linkshared` and `linkstatic` attributes are passed booleans now instead of ints, making the command more directly interpretable to the human reader.

The fix was suggested by @junyer in the corresponding GitHub issue thread https://github.com/google/benchmark/issues/1367 - thank you for the suggestion!
2022-03-14 12:22:45 +00:00
Vy Nguyen 4a1943d611
Update LICENSE file to clearly state which file needs BSD 3 (#1366)
Follow up to PR/1363
2022-03-14 09:50:46 +00:00
Bensuperpc 4f77cf9e62
Fix float comparaison and add float comparison warning (#1368)
GCC warns about comparison with zero, clang does not.
2022-03-12 19:05:23 +03:00
Nicholas Junge 705202d22a
Add PyPI upload job to wheel building workflow (#1359)
This commit adds a job running after the wheel building job responsible for uploading the built wheels to PyPI.
The job only runs on successful completion of all build jobs, and uploads to PyPI using a secret added to the Google Benchmark repo (TBD).
Also, the setup-python action has been bumped to the latest version v3.
2022-03-10 16:56:55 +00:00
Vy Nguyen a25f3cded7
Appended additional BSD 3-Clause to LICENSE (#1363)
Needed for export_header module
2022-03-09 17:51:11 +00:00
Vy Nguyen eacce0b503
Add SetBenchmarkFilter() to set --benchmark_filter flag value in user code (#1362)
* Add SetBenchmarkFilter() to set --benchmark_filter flag value in user code.

Use case:  Provide an API to set this flag indepedence of the flag's implementation (ie., absl flag vs benchmark's flag facility)

* add test

* added notes on Initialize()
2022-03-08 16:02:37 +00:00
Nicholas Junge df7749cd09
Add long description and content type for proper PyPI presentation (#1361)
This commit adds the two fields `long_description` and `long_description_content_type` to `setup.py`. These can be used for proper project presentation on the PyPI project page, which is currently a placeholder.
2022-03-08 12:40:14 +00:00
Bátor Tallér d08e7b6056
Allow setting the default time unit globally (#1337)
* Add option to set the default time unit globally

This commit introduces the `--benchmark_time_unit={ns|us|ms|s}` command line argument. The argument only affects benchmarks where the time unit is not set explicitly.

* Update AUTHORS and CONTRIBUTORS

* Test `SetDefaultTimeUnit`

* clang format

* Use `GetDefaultTimeUnit()` for initializing `TimeUnit` variables

* Review fixes

* Export functions

* Add comment
2022-03-04 11:07:01 +00:00
Sergiu Deitsch e33986a000
restore BENCHMARK_MAIN() (#1357) 2022-02-26 10:17:13 +00:00
Paul Wankadia 7cb2914292
@platforms is magical; remove it from WORKSPACE. (#1356) 2022-02-24 15:06:45 +00:00
Paul Wankadia e057a7cee2
Make generate_export_header.bzl work for Windows. (#1355)
* Make generate_export_header.bzl work for Windows.

While I'm here, bring the generated code slightly closer to what CMake
would generate nowadays.

Fixes #1351.

* Fix define.

* Fix export_import_condition.

* Fix guard.
2022-02-24 14:42:59 +00:00
Dominic Hamon e82a6ed704
avoid case sensitive issues with duplicated names (#1354) 2022-02-22 13:53:29 +00:00
Dominic Hamon b46208fcf0
move bzl file out of tools (#1352) 2022-02-21 12:03:18 +00:00
Vincenzo Palazzo c563644040
Introduce the possibility to customize the help printer function (#1342)
* introduce the possibility to customize the help printer function

Signed-off-by: Vincenzo Palazzo <vincenzopalazzodev@gmail.com>

* fixed naming convertion, and introduce the option function in the init method

Signed-off-by: Vincenzo Palazzo <vincenzopalazzodev@gmail.com>

* remove the macros to inject the helper function

Signed-off-by: Vincenzo Palazzo <vincenzopalazzodev@gmail.com>

* remove the default implementation, and introduce the nullprt

Signed-off-by: Vincenzo Palazzo <vincenzopalazzodev@gmail.com>
2022-02-16 09:23:54 +00:00
Dominic Hamon 28b210ebb8
simplify reference to internal path (#1349) 2022-02-15 14:06:31 +00:00
Vy Nguyen 7b46d3ddbf
Check for macro existence before using (#1347) 2022-02-14 17:00:44 +00:00
Sergiu Deitsch 9e47d070fe
annotate and export public symbols (#1321) 2022-02-14 10:48:53 +00:00
Dominic Hamon 6e51dcbcc3
Expose default display reporter creation in public API (#1344)
* Expose default display reporter creation in public API

this is useful when a custom reporter wants to fall back on the default
display reporter, but doesn't necessarily have access to the benchmark
library flag configuration.

* Make use of unique_ptr in the random interleaving test.

* clang-format
2022-02-11 10:23:05 +00:00
staffantj d2cbd4b26a
Avoid potential truncation issues for the integral type parameterized tests. (#1341)
* The parameterized tests check both floating point and integral types. We might as well use types that avoid truncation warnings across the platforms

* static_cast version of how to avoid truncation warnings in basic_test

Co-authored-by: Staffan Tjernstrom <staffantj@users.noreply.github.com>
2022-02-08 16:40:43 +00:00
Liqiang TAO bdea5051b0
Add mutex when reading counters_ (Fixes #1335) (#1338) 2022-02-07 13:03:19 +00:00
batortaller 1ee7bee6c5
Use Win32 API only for Win32 apps (#1333) 2022-02-02 12:16:19 +03:00
Dominic Hamon 14eee07f4a
bump numby, as per dependabot (#1336) 2022-01-31 10:28:11 +00:00
Nicholas Junge 6d51a119ff
Fix cross compilation for macOS ARM builds in cibuildwheel (#1334)
This commit contains a fix for macOS ARM64 wheel buils in Google Benchmark's wheel building CI.

Previously, while `cibuildwheel` itself properly identified the need for cross-compilations and produced valid ARM platform wheels, the included shared library containing the Python bindings
built by `bazel` was built for x86, resulting in immediate errors upon import.

To fix this, logic was added to the setup.py file that adds the "--cpu=darwin_arm64" and "--macos_cpus=arm64" switches to the `bazel build` command if
1) The current system platform is macOS Darwin running on the x86_64 architecture, and
2) The ARCHFLAGS environment variable, set by wheel build systems like conda and cibuildwheel, contains the tag "arm64".

This way, bazel correctly sets the target CPU to ARM64, and produces functional wheels for the macOS ARM line of CPUs.
2022-01-26 09:13:26 +00:00