Skip to content

Commit

Permalink
Merge branch 'google:main' into i1807-dont-clobber-existing-manager
Browse files Browse the repository at this point in the history
  • Loading branch information
xdje42 authored Oct 23, 2024
2 parents b66b20b + be21345 commit 9bb6adf
Show file tree
Hide file tree
Showing 20 changed files with 169 additions and 83 deletions.
21 changes: 15 additions & 6 deletions .github/workflows/wheels.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
- name: Install Python 3.12
uses: actions/setup-python@v5
with:
python-version: 3.12
python-version: "3.12"
- run: python -m pip install build
- name: Build sdist
run: python -m build --sdist
Expand All @@ -40,16 +40,23 @@ jobs:
with:
fetch-depth: 0

- uses: actions/setup-python@v5
name: Install Python 3.12
with:
python-version: "3.12"
- run: pip install --upgrade pip uv

- name: Set up QEMU
if: runner.os == 'Linux'
uses: docker/setup-qemu-action@v3
with:
platforms: all

- name: Build wheels on ${{ matrix.os }} using cibuildwheel
uses: pypa/cibuildwheel@v2.17
uses: pypa/cibuildwheel@v2.20
env:
CIBW_BUILD: "cp38-* cp39-* cp310-* cp311-* cp312-*"
CIBW_BUILD: "cp310-* cp311-* cp312-*"
CIBW_BUILD_FRONTEND: "build[uv]"
CIBW_SKIP: "*-musllinux_*"
CIBW_TEST_SKIP: "cp38-macosx_*:arm64"
CIBW_ARCHS_LINUX: auto64 aarch64
Expand All @@ -58,6 +65,8 @@ jobs:
# Grab the rootless Bazel installation inside the container.
CIBW_ENVIRONMENT_LINUX: PATH=$PATH:$HOME/bin
CIBW_TEST_COMMAND: python {project}/bindings/python/google_benchmark/example.py
# unused by Bazel, but needed explicitly by delocate on MacOS.
MACOSX_DEPLOYMENT_TARGET: "10.14"

- name: Upload Google Benchmark ${{ matrix.os }} wheels
uses: actions/upload-artifact@v4
Expand All @@ -81,11 +90,11 @@ jobs:
name: Publish google-benchmark wheels to PyPI
needs: [merge_wheels]
runs-on: ubuntu-latest
if: github.event_name == 'release' && github.event.action == 'published'
permissions:
id-token: write
steps:
- uses: actions/download-artifact@v4
with:
path: dist
- uses: pypa/gh-action-pypi-publish@release/v1
with:
user: __token__
password: ${{ secrets.PYPI_PASSWORD }}
6 changes: 3 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
repos:
- repo: https://github.com/keith/pre-commit-buildifier
rev: 6.4.0
rev: 7.1.2
hooks:
- id: buildifier
- id: buildifier-lint
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.11.0
rev: v1.11.1
hooks:
- id: mypy
types_or: [ python, pyi ]
args: [ "--ignore-missing-imports", "--scripts-are-modules" ]
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.4.10
rev: v0.6.1
hooks:
- id: ruff
args: [ --fix, --exit-non-zero-on-fix ]
Expand Down
8 changes: 6 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Require CMake 3.10. If available, use the policies up to CMake 3.22.
cmake_minimum_required (VERSION 3.10...3.22)

project (benchmark VERSION 1.8.5 LANGUAGES CXX)
project (benchmark VERSION 1.9.0 LANGUAGES CXX)

option(BENCHMARK_ENABLE_TESTING "Enable testing of the benchmark library." ON)
option(BENCHMARK_ENABLE_EXCEPTIONS "Enable the use of exceptions in the benchmark library." ON)
Expand Down Expand Up @@ -147,9 +147,13 @@ set(CMAKE_CXX_EXTENSIONS OFF)
if (MSVC)
# Turn compiler warnings up to 11
string(REGEX REPLACE "[-/]W[1-4]" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W4")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W4 /MP")
add_definitions(-D_CRT_SECURE_NO_WARNINGS)

if(BENCHMARK_ENABLE_WERROR)
add_cxx_compiler_flag(-WX)
endif()

if (NOT BENCHMARK_ENABLE_EXCEPTIONS)
add_cxx_compiler_flag(-EHs-)
add_cxx_compiler_flag(-EHa-)
Expand Down
12 changes: 6 additions & 6 deletions MODULE.bazel
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
module(
name = "google_benchmark",
version = "1.8.5",
version = "1.9.0",
)

bazel_dep(name = "bazel_skylib", version = "1.5.0")
bazel_dep(name = "platforms", version = "0.0.8")
bazel_dep(name = "bazel_skylib", version = "1.7.1")
bazel_dep(name = "platforms", version = "0.0.10")
bazel_dep(name = "rules_foreign_cc", version = "0.10.1")
bazel_dep(name = "rules_cc", version = "0.0.9")

bazel_dep(name = "rules_python", version = "0.31.0", dev_dependency = True)
bazel_dep(name = "googletest", version = "1.12.1", dev_dependency = True, repo_name = "com_google_googletest")
bazel_dep(name = "rules_python", version = "0.37.0", dev_dependency = True)
bazel_dep(name = "googletest", version = "1.14.0", dev_dependency = True, repo_name = "com_google_googletest")

bazel_dep(name = "libpfm", version = "4.11.0")

Expand Down Expand Up @@ -38,4 +38,4 @@ use_repo(pip, "tools_pip_deps")

# -- bazel_dep definitions -- #

bazel_dep(name = "nanobind_bazel", version = "2.1.0", dev_dependency = True)
bazel_dep(name = "nanobind_bazel", version = "2.2.0", dev_dependency = True)
3 changes: 2 additions & 1 deletion bindings/python/google_benchmark/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ def my_benchmark(state):
oNone as oNone,
oNSquared as oNSquared,
)
from google_benchmark.version import __version__ as __version__

__version__ = "1.9.0"


class __OptionMaker:
Expand Down
1 change: 1 addition & 0 deletions bindings/python/google_benchmark/example.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ def skipped(state):


@benchmark.register
@benchmark.option.use_manual_time()
def manual_timing(state):
while state:
# Manually count Python CPU time
Expand Down
7 changes: 0 additions & 7 deletions bindings/python/google_benchmark/version.py

This file was deleted.

2 changes: 1 addition & 1 deletion cmake/benchmark.pc.in
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ includedir=@CMAKE_INSTALL_FULL_INCLUDEDIR@

Name: @PROJECT_NAME@
Description: Google microbenchmark framework
Version: @VERSION@
Version: @NORMALIZED_VERSION@

Libs: -L${libdir} -lbenchmark
Libs.private: -lpthread @BENCHMARK_PRIVATE_LINK_LIBRARIES@
Expand Down
2 changes: 1 addition & 1 deletion cmake/benchmark_main.pc.in
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ libdir=@CMAKE_INSTALL_FULL_LIBDIR@

Name: @PROJECT_NAME@
Description: Google microbenchmark framework (with main() function)
Version: @VERSION@
Version: @NORMALIZED_VERSION@
Requires: benchmark
Libs: -L${libdir} -lbenchmark_main
6 changes: 6 additions & 0 deletions docs/dependencies.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,9 @@ distributions include newer versions, for example:
* Ubuntu 20.04 provides CMake 3.16.3
* Debian 11.4 provides CMake 3.18.4
* Ubuntu 22.04 provides CMake 3.22.1

## Python

The Python bindings require Python 3.10+ as of v1.9.0 (2024-08-16) for installation from PyPI.
Building from source for older versions probably still works, though. See the [user guide](python_bindings.md) for details on how to build from source.
The minimum theoretically supported version is Python 3.8, since the used bindings generator (nanobind) only supports Python 3.8+.
19 changes: 13 additions & 6 deletions docs/releasing.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,24 @@
* `git log $(git describe --abbrev=0 --tags)..HEAD` gives you the list of
commits between the last annotated tag and HEAD
* Pick the most interesting.
* Create one last commit that updates the version saved in `CMakeLists.txt` and `MODULE.bazel`
to the release version you're creating. (This version will be used if benchmark is installed
from the archive you'll be creating in the next step.)
* Create one last commit that updates the version saved in `CMakeLists.txt`, `MODULE.bazel`,
and `bindings/python/google_benchmark/__init__.py` to the release version you're creating.
(This version will be used if benchmark is installed from the archive you'll be creating
in the next step.)

```
project (benchmark VERSION 1.8.0 LANGUAGES CXX)
# CMakeLists.txt
project (benchmark VERSION 1.9.0 LANGUAGES CXX)
```

```
module(name = "com_github_google_benchmark", version="1.8.0")
# MODULE.bazel
module(name = "com_github_google_benchmark", version="1.9.0")
```

```
# google_benchmark/__init__.py
__version__ = "1.9.0"
```

* Create a release through github's interface
Expand All @@ -28,4 +36,3 @@ module(name = "com_github_google_benchmark", version="1.8.0")
* `git push --force --tags origin`
* Confirm that the "Build and upload Python wheels" action runs to completion
* Run it manually if it hasn't run.
* IMPORTANT: When re-running manually, make sure to select the newly created `<tag>` as the workflow version in the "Run workflow" tab on the GitHub Actions page.
13 changes: 10 additions & 3 deletions docs/user_guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,9 @@ tabular data on stdout. Example tabular output looks like:
```
Benchmark Time(ns) CPU(ns) Iterations
----------------------------------------------------------------------
BM_SetInsert/1024/1 28928 29349 23853 133.097kB/s 33.2742k items/s
BM_SetInsert/1024/8 32065 32913 21375 949.487kB/s 237.372k items/s
BM_SetInsert/1024/10 33157 33648 21431 1.13369MB/s 290.225k items/s
BM_SetInsert/1024/1 28928 29349 23853 133.097kiB/s 33.2742k items/s
BM_SetInsert/1024/8 32065 32913 21375 949.487kiB/s 237.372k items/s
BM_SetInsert/1024/10 33157 33648 21431 1.13369MiB/s 290.225k items/s
```

The JSON format outputs human readable json split into two top level attributes.
Expand Down Expand Up @@ -167,6 +167,13 @@ line interface or by setting environment variables before execution. For every
prevails). A complete list of CLI options is available running benchmarks
with the `--help` switch.

### Dry runs

To confirm that benchmarks can run successfully without needing to wait for
multiple repetitions and iterations, the `--benchmark_dry_run` flag can be
used. This will run the benchmarks as normal, but for 1 iteration and 1
repetition only.

<a name="running-a-subset-of-benchmarks" />

## Running a Subset of Benchmarks
Expand Down
52 changes: 50 additions & 2 deletions include/benchmark/benchmark.h
Original file line number Diff line number Diff line change
Expand Up @@ -290,11 +290,50 @@ BENCHMARK(BM_test)->Unit(benchmark::kMillisecond);
#define BENCHMARK_OVERRIDE
#endif

#if defined(__GNUC__)
// Determine the cacheline size based on architecture
#if defined(__i386__) || defined(__x86_64__)
#define BENCHMARK_INTERNAL_CACHELINE_SIZE 64
#elif defined(__powerpc64__)
#define BENCHMARK_INTERNAL_CACHELINE_SIZE 128
#elif defined(__aarch64__)
#define BENCHMARK_INTERNAL_CACHELINE_SIZE 64
#elif defined(__arm__)
// Cache line sizes for ARM: These values are not strictly correct since
// cache line sizes depend on implementations, not architectures. There
// are even implementations with cache line sizes configurable at boot
// time.
#if defined(__ARM_ARCH_5T__)
#define BENCHMARK_INTERNAL_CACHELINE_SIZE 32
#elif defined(__ARM_ARCH_7A__)
#define BENCHMARK_INTERNAL_CACHELINE_SIZE 64
#endif // ARM_ARCH
#endif // arches
#endif // __GNUC__

#ifndef BENCHMARK_INTERNAL_CACHELINE_SIZE
// A reasonable default guess. Note that overestimates tend to waste more
// space, while underestimates tend to waste more time.
#define BENCHMARK_INTERNAL_CACHELINE_SIZE 64
#endif

#if defined(__GNUC__)
// Indicates that the declared object be cache aligned using
// `BENCHMARK_INTERNAL_CACHELINE_SIZE` (see above).
#define BENCHMARK_INTERNAL_CACHELINE_ALIGNED \
__attribute__((aligned(BENCHMARK_INTERNAL_CACHELINE_SIZE)))
#elif defined(_MSC_VER)
#define BENCHMARK_INTERNAL_CACHELINE_ALIGNED \
__declspec(align(BENCHMARK_INTERNAL_CACHELINE_SIZE))
#else
#define BENCHMARK_INTERNAL_CACHELINE_ALIGNED
#endif

#if defined(_MSC_VER)
#pragma warning(push)
// C4251: <symbol> needs to have dll-interface to be used by clients of class
#pragma warning(disable : 4251)
#endif
#endif // _MSC_VER_

namespace benchmark {
class BenchmarkReporter;
Expand Down Expand Up @@ -757,9 +796,14 @@ enum Skipped

} // namespace internal

#if defined(_MSC_VER)
#pragma warning(push)
// C4324: 'benchmark::State': structure was padded due to alignment specifier
#pragma warning(disable : 4324)
#endif // _MSC_VER_
// State is passed to a running Benchmark and contains state for the
// benchmark to use.
class BENCHMARK_EXPORT State {
class BENCHMARK_EXPORT BENCHMARK_INTERNAL_CACHELINE_ALIGNED State {
public:
struct StateIterator;
friend struct StateIterator;
Expand Down Expand Up @@ -1024,6 +1068,9 @@ class BENCHMARK_EXPORT State {

friend class internal::BenchmarkInstance;
};
#if defined(_MSC_VER)
#pragma warning(pop)
#endif // _MSC_VER_

inline BENCHMARK_ALWAYS_INLINE bool State::KeepRunning() {
return KeepRunningInternal(1, /*is_batch=*/false);
Expand Down Expand Up @@ -1507,6 +1554,7 @@ class Fixture : public internal::Benchmark {
BaseClass##_##Method##_Benchmark

#define BENCHMARK_PRIVATE_DECLARE(n) \
/* NOLINTNEXTLINE(misc-use-anonymous-namespace) */ \
static ::benchmark::internal::Benchmark* BENCHMARK_PRIVATE_NAME(n) \
BENCHMARK_UNUSED

Expand Down
25 changes: 8 additions & 17 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,25 +1,21 @@
[build-system]
requires = ["setuptools", "setuptools-scm[toml]", "wheel"]
requires = ["setuptools<73"]
build-backend = "setuptools.build_meta"

[project]
name = "google_benchmark"
description = "A library to benchmark code snippets."
requires-python = ">=3.8"
license = {file = "LICENSE"}
requires-python = ">=3.10"
license = { file = "LICENSE" }
keywords = ["benchmark"]

authors = [
{name = "Google", email = "[email protected]"},
]
authors = [{ name = "Google", email = "[email protected]" }]

classifiers = [
"Development Status :: 4 - Beta",
"Intended Audience :: Developers",
"Intended Audience :: Science/Research",
"License :: OSI Approved :: Apache Software License",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
Expand All @@ -29,14 +25,10 @@ classifiers = [

dynamic = ["readme", "version"]

dependencies = [
"absl-py>=0.7.1",
]
dependencies = ["absl-py>=0.7.1"]

[project.optional-dependencies]
dev = [
"pre-commit>=3.3.3",
]
dev = ["pre-commit>=3.3.3"]

[project.urls]
Homepage = "https://github.com/google/benchmark"
Expand All @@ -45,16 +37,15 @@ Repository = "https://github.com/google/benchmark.git"
Discord = "https://discord.gg/cz7UX7wKC2"

[tool.setuptools]
package-dir = {"" = "bindings/python"}
package-dir = { "" = "bindings/python" }
zip-safe = false

[tool.setuptools.packages.find]
where = ["bindings/python"]

[tool.setuptools.dynamic]
readme = { file = "README.md", content-type = "text/markdown" }

[tool.setuptools_scm]
version = { attr = "google_benchmark.__version__" }

[tool.mypy]
check_untyped_defs = true
Expand Down
Loading

0 comments on commit 9bb6adf

Please sign in to comment.