mirror of
https://github.com/google/benchmark.git
synced 2024-12-26 20:40:21 +08:00
986423a62d
Some checks failed
bazel / bazel.${{ matrix.os }}.${{ matrix.bzlmod && 'bzlmod' || 'no_bzlmod' }} (false, macos-latest) (push) Has been cancelled
bazel / bazel.${{ matrix.os }}.${{ matrix.bzlmod && 'bzlmod' || 'no_bzlmod' }} (false, ubuntu-latest) (push) Has been cancelled
bazel / bazel.${{ matrix.os }}.${{ matrix.bzlmod && 'bzlmod' || 'no_bzlmod' }} (false, windows-latest) (push) Has been cancelled
bazel / bazel.${{ matrix.os }}.${{ matrix.bzlmod && 'bzlmod' || 'no_bzlmod' }} (true, macos-latest) (push) Has been cancelled
bazel / bazel.${{ matrix.os }}.${{ matrix.bzlmod && 'bzlmod' || 'no_bzlmod' }} (true, ubuntu-latest) (push) Has been cancelled
bazel / bazel.${{ matrix.os }}.${{ matrix.bzlmod && 'bzlmod' || 'no_bzlmod' }} (true, windows-latest) (push) Has been cancelled
build-and-test-min-cmake / ${{ matrix.os }}.min-cmake (macos-latest) (push) Has been cancelled
build-and-test-min-cmake / ${{ matrix.os }}.min-cmake (ubuntu-latest) (push) Has been cancelled
build-and-test-perfcounters / ${{ matrix.os }}.${{ matrix.build_type }} (Debug, ubuntu-20.04) (push) Has been cancelled
build-and-test-perfcounters / ${{ matrix.os }}.${{ matrix.build_type }} (Debug, ubuntu-22.04) (push) Has been cancelled
build-and-test-perfcounters / ${{ matrix.os }}.${{ matrix.build_type }} (Release, ubuntu-20.04) (push) Has been cancelled
build-and-test-perfcounters / ${{ matrix.os }}.${{ matrix.build_type }} (Release, ubuntu-22.04) (push) Has been cancelled
build-and-test / ${{ matrix.os }}.${{ matrix.build_type }}.${{ matrix.lib }}.${{ matrix.compiler }} (Debug, clang++, shared, macos-latest) (push) Has been cancelled
build-and-test / ${{ matrix.os }}.${{ matrix.build_type }}.${{ matrix.lib }}.${{ matrix.compiler }} (Debug, clang++, shared, ubuntu-20.04) (push) Has been cancelled
build-and-test / ${{ matrix.os }}.${{ matrix.build_type }}.${{ matrix.lib }}.${{ matrix.compiler }} (Debug, clang++, shared, ubuntu-22.04) (push) Has been cancelled
build-and-test / ${{ matrix.os }}.${{ matrix.build_type }}.${{ matrix.lib }}.${{ matrix.compiler }} (Debug, clang++, static, macos-latest) (push) Has been cancelled
build-and-test / ${{ matrix.os }}.${{ matrix.build_type }}.${{ matrix.lib }}.${{ matrix.compiler }} (Debug, clang++, static, ubuntu-20.04) (push) Has been cancelled
build-and-test / ${{ matrix.os }}.${{ matrix.build_type }}.${{ matrix.lib }}.${{ matrix.compiler }} (Debug, clang++, static, ubuntu-22.04) (push) Has been cancelled
build-and-test / ${{ matrix.os }}.${{ matrix.build_type }}.${{ matrix.lib }}.${{ matrix.compiler }} (Debug, g++, shared, macos-latest) (push) Has been cancelled
build-and-test / ${{ matrix.os }}.${{ matrix.build_type }}.${{ matrix.lib }}.${{ matrix.compiler }} (Debug, g++, shared, ubuntu-20.04) (push) Has been cancelled
build-and-test / ${{ matrix.os }}.${{ matrix.build_type }}.${{ matrix.lib }}.${{ matrix.compiler }} (Debug, g++, shared, ubuntu-22.04) (push) Has been cancelled
build-and-test / ${{ matrix.os }}.${{ matrix.build_type }}.${{ matrix.lib }}.${{ matrix.compiler }} (Debug, g++, static, macos-latest) (push) Has been cancelled
build-and-test / ${{ matrix.os }}.${{ matrix.build_type }}.${{ matrix.lib }}.${{ matrix.compiler }} (Debug, g++, static, ubuntu-20.04) (push) Has been cancelled
build-and-test / ${{ matrix.os }}.${{ matrix.build_type }}.${{ matrix.lib }}.${{ matrix.compiler }} (Debug, g++, static, ubuntu-22.04) (push) Has been cancelled
build-and-test / ${{ matrix.os }}.${{ matrix.build_type }}.${{ matrix.lib }}.${{ matrix.compiler }} (Release, clang++, shared, macos-latest) (push) Has been cancelled
build-and-test / ${{ matrix.os }}.${{ matrix.build_type }}.${{ matrix.lib }}.${{ matrix.compiler }} (Release, clang++, shared, ubuntu-20.04) (push) Has been cancelled
build-and-test / ${{ matrix.os }}.${{ matrix.build_type }}.${{ matrix.lib }}.${{ matrix.compiler }} (Release, clang++, shared, ubuntu-22.04) (push) Has been cancelled
build-and-test / ${{ matrix.os }}.${{ matrix.build_type }}.${{ matrix.lib }}.${{ matrix.compiler }} (Release, clang++, static, macos-latest) (push) Has been cancelled
build-and-test / ${{ matrix.os }}.${{ matrix.build_type }}.${{ matrix.lib }}.${{ matrix.compiler }} (Release, clang++, static, ubuntu-20.04) (push) Has been cancelled
build-and-test / ${{ matrix.os }}.${{ matrix.build_type }}.${{ matrix.lib }}.${{ matrix.compiler }} (Release, clang++, static, ubuntu-22.04) (push) Has been cancelled
build-and-test / ${{ matrix.os }}.${{ matrix.build_type }}.${{ matrix.lib }}.${{ matrix.compiler }} (Release, g++, shared, macos-latest) (push) Has been cancelled
build-and-test / ${{ matrix.os }}.${{ matrix.build_type }}.${{ matrix.lib }}.${{ matrix.compiler }} (Release, g++, shared, ubuntu-20.04) (push) Has been cancelled
build-and-test / ${{ matrix.os }}.${{ matrix.build_type }}.${{ matrix.lib }}.${{ matrix.compiler }} (Release, g++, shared, ubuntu-22.04) (push) Has been cancelled
build-and-test / ${{ matrix.os }}.${{ matrix.build_type }}.${{ matrix.lib }}.${{ matrix.compiler }} (Release, g++, static, macos-latest) (push) Has been cancelled
build-and-test / ${{ matrix.os }}.${{ matrix.build_type }}.${{ matrix.lib }}.${{ matrix.compiler }} (Release, g++, static, ubuntu-20.04) (push) Has been cancelled
build-and-test / ${{ matrix.os }}.${{ matrix.build_type }}.${{ matrix.lib }}.${{ matrix.compiler }} (Release, g++, static, ubuntu-22.04) (push) Has been cancelled
build-and-test / ${{ matrix.os }}.${{ matrix.build_type }}.${{ matrix.lib }}.${{ matrix.msvc }} (x64, Debug, Visual Studio 16 2019, shared, VS-16-2019, windows-2019) (push) Has been cancelled
build-and-test / ${{ matrix.os }}.${{ matrix.build_type }}.${{ matrix.lib }}.${{ matrix.msvc }} (x64, Debug, Visual Studio 16 2019, static, VS-16-2019, windows-2019) (push) Has been cancelled
build-and-test / ${{ matrix.os }}.${{ matrix.build_type }}.${{ matrix.lib }}.${{ matrix.msvc }} (x64, Debug, Visual Studio 17 2022, shared, VS-17-2022, windows-2022) (push) Has been cancelled
build-and-test / ${{ matrix.os }}.${{ matrix.build_type }}.${{ matrix.lib }}.${{ matrix.msvc }} (x64, Debug, Visual Studio 17 2022, static, VS-17-2022, windows-2022) (push) Has been cancelled
build-and-test / ${{ matrix.os }}.${{ matrix.build_type }}.${{ matrix.lib }}.${{ matrix.msvc }} (x64, Release, Visual Studio 16 2019, shared, VS-16-2019, windows-2019) (push) Has been cancelled
build-and-test / ${{ matrix.os }}.${{ matrix.build_type }}.${{ matrix.lib }}.${{ matrix.msvc }} (x64, Release, Visual Studio 16 2019, static, VS-16-2019, windows-2019) (push) Has been cancelled
build-and-test / ${{ matrix.os }}.${{ matrix.build_type }}.${{ matrix.lib }}.${{ matrix.msvc }} (x64, Release, Visual Studio 17 2022, shared, VS-17-2022, windows-2022) (push) Has been cancelled
build-and-test / ${{ matrix.os }}.${{ matrix.build_type }}.${{ matrix.lib }}.${{ matrix.msvc }} (x64, Release, Visual Studio 17 2022, static, VS-17-2022, windows-2022) (push) Has been cancelled
build-and-test / ${{ matrix.os }}.${{ matrix.build_type }}.${{ matrix.lib }}.${{ matrix.msys2.msystem }} (Debug, shared, map[arch:i686 compiler:clang++ family:LLVM msystem:CLANG32], windows-latest) (push) Has been cancelled
build-and-test / ${{ matrix.os }}.${{ matrix.build_type }}.${{ matrix.lib }}.${{ matrix.msys2.msystem }} (Debug, shared, map[arch:i686 compiler:g++ family:GNU msystem:MINGW32], windows-latest) (push) Has been cancelled
build-and-test / ${{ matrix.os }}.${{ matrix.build_type }}.${{ matrix.lib }}.${{ matrix.msys2.msystem }} (Debug, shared, map[arch:x86_64 compiler:clang++ family:LLVM msystem:CLANG64], windows-latest) (push) Has been cancelled
build-and-test / ${{ matrix.os }}.${{ matrix.build_type }}.${{ matrix.lib }}.${{ matrix.msys2.msystem }} (Debug, shared, map[arch:x86_64 compiler:g++ family:GNU msystem:MINGW64], windows-latest) (push) Has been cancelled
build-and-test / ${{ matrix.os }}.${{ matrix.build_type }}.${{ matrix.lib }}.${{ matrix.msys2.msystem }} (Debug, shared, map[arch:x86_64 compiler:g++ family:GNU msystem:UCRT64], windows-latest) (push) Has been cancelled
build-and-test / ${{ matrix.os }}.${{ matrix.build_type }}.${{ matrix.lib }}.${{ matrix.msys2.msystem }} (Debug, static, map[arch:i686 compiler:clang++ family:LLVM msystem:CLANG32], windows-latest) (push) Has been cancelled
build-and-test / ${{ matrix.os }}.${{ matrix.build_type }}.${{ matrix.lib }}.${{ matrix.msys2.msystem }} (Debug, static, map[arch:i686 compiler:g++ family:GNU msystem:MINGW32], windows-latest) (push) Has been cancelled
build-and-test / ${{ matrix.os }}.${{ matrix.build_type }}.${{ matrix.lib }}.${{ matrix.msys2.msystem }} (Debug, static, map[arch:x86_64 compiler:clang++ family:LLVM msystem:CLANG64], windows-latest) (push) Has been cancelled
build-and-test / ${{ matrix.os }}.${{ matrix.build_type }}.${{ matrix.lib }}.${{ matrix.msys2.msystem }} (Debug, static, map[arch:x86_64 compiler:g++ family:GNU msystem:MINGW64], windows-latest) (push) Has been cancelled
build-and-test / ${{ matrix.os }}.${{ matrix.build_type }}.${{ matrix.lib }}.${{ matrix.msys2.msystem }} (Debug, static, map[arch:x86_64 compiler:g++ family:GNU msystem:UCRT64], windows-latest) (push) Has been cancelled
build-and-test / ${{ matrix.os }}.${{ matrix.build_type }}.${{ matrix.lib }}.${{ matrix.msys2.msystem }} (Release, shared, map[arch:i686 compiler:clang++ family:LLVM msystem:CLANG32], windows-latest) (push) Has been cancelled
build-and-test / ${{ matrix.os }}.${{ matrix.build_type }}.${{ matrix.lib }}.${{ matrix.msys2.msystem }} (Release, shared, map[arch:i686 compiler:g++ family:GNU msystem:MINGW32], windows-latest) (push) Has been cancelled
build-and-test / ${{ matrix.os }}.${{ matrix.build_type }}.${{ matrix.lib }}.${{ matrix.msys2.msystem }} (Release, shared, map[arch:x86_64 compiler:clang++ family:LLVM msystem:CLANG64], windows-latest) (push) Has been cancelled
build-and-test / ${{ matrix.os }}.${{ matrix.build_type }}.${{ matrix.lib }}.${{ matrix.msys2.msystem }} (Release, shared, map[arch:x86_64 compiler:g++ family:GNU msystem:MINGW64], windows-latest) (push) Has been cancelled
build-and-test / ${{ matrix.os }}.${{ matrix.build_type }}.${{ matrix.lib }}.${{ matrix.msys2.msystem }} (Release, shared, map[arch:x86_64 compiler:g++ family:GNU msystem:UCRT64], windows-latest) (push) Has been cancelled
build-and-test / ${{ matrix.os }}.${{ matrix.build_type }}.${{ matrix.lib }}.${{ matrix.msys2.msystem }} (Release, static, map[arch:i686 compiler:clang++ family:LLVM msystem:CLANG32], windows-latest) (push) Has been cancelled
build-and-test / ${{ matrix.os }}.${{ matrix.build_type }}.${{ matrix.lib }}.${{ matrix.msys2.msystem }} (Release, static, map[arch:i686 compiler:g++ family:GNU msystem:MINGW32], windows-latest) (push) Has been cancelled
build-and-test / ${{ matrix.os }}.${{ matrix.build_type }}.${{ matrix.lib }}.${{ matrix.msys2.msystem }} (Release, static, map[arch:x86_64 compiler:clang++ family:LLVM msystem:CLANG64], windows-latest) (push) Has been cancelled
build-and-test / ${{ matrix.os }}.${{ matrix.build_type }}.${{ matrix.lib }}.${{ matrix.msys2.msystem }} (Release, static, map[arch:x86_64 compiler:g++ family:GNU msystem:MINGW64], windows-latest) (push) Has been cancelled
build-and-test / ${{ matrix.os }}.${{ matrix.build_type }}.${{ matrix.lib }}.${{ matrix.msys2.msystem }} (Release, static, map[arch:x86_64 compiler:g++ family:GNU msystem:UCRT64], windows-latest) (push) Has been cancelled
clang-format-lint / check-clang-format (push) Has been cancelled
clang-tidy / run-clang-tidy (push) Has been cancelled
doxygen / Build HTML documentation (push) Has been cancelled
python + Bazel pre-commit checks / pre-commit (push) Has been cancelled
sanitizer / ${{ matrix.sanitizer }}.${{ matrix.build_type }} (Debug, asan) (push) Has been cancelled
sanitizer / ${{ matrix.sanitizer }}.${{ matrix.build_type }} (Debug, msan) (push) Has been cancelled
sanitizer / ${{ matrix.sanitizer }}.${{ matrix.build_type }} (Debug, tsan) (push) Has been cancelled
sanitizer / ${{ matrix.sanitizer }}.${{ matrix.build_type }} (Debug, ubsan) (push) Has been cancelled
sanitizer / ${{ matrix.sanitizer }}.${{ matrix.build_type }} (RelWithDebInfo, asan) (push) Has been cancelled
sanitizer / ${{ matrix.sanitizer }}.${{ matrix.build_type }} (RelWithDebInfo, msan) (push) Has been cancelled
sanitizer / ${{ matrix.sanitizer }}.${{ matrix.build_type }} (RelWithDebInfo, tsan) (push) Has been cancelled
sanitizer / ${{ matrix.sanitizer }}.${{ matrix.build_type }} (RelWithDebInfo, ubsan) (push) Has been cancelled
test-bindings / Test GBM Python bindings on ${{ matrix.os }} (macos-latest) (push) Has been cancelled
test-bindings / Test GBM Python bindings on ${{ matrix.os }} (ubuntu-latest) (push) Has been cancelled
test-bindings / Test GBM Python bindings on ${{ matrix.os }} (windows-latest) (push) Has been cancelled
* Supply MacOS deployment target to delocate, use build+uv frontend This shaves off multiple minutes from the wheel builds alone. Also revert to trusted publishing for wheel uploads as it is now set up. * Bump oldest supported Python to 3.10, eliminate setuptools-scm The version is now a string again, under the same attribute as it was before. This is a pragmatic decision in order to be able to upload wheels again, possibly directly from main. We could in the future also set the Python version to a development version if we want to avoid accidental uploads of `main`. * Add a note on supported Python versions in the docs Also fixes the setuptools failure observed in the latest CI by pinning to the last version before v73 until the problem is identified and resolved.
143 lines
4.3 KiB
Python
143 lines
4.3 KiB
Python
# Copyright 2020 Google Inc. All rights reserved.
|
|
#
|
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
# you may not use this file except in compliance with the License.
|
|
# You may obtain a copy of the License at
|
|
#
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
#
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
# See the License for the specific language governing permissions and
|
|
# limitations under the License.
|
|
"""Python benchmarking utilities.
|
|
|
|
Example usage:
|
|
import google_benchmark as benchmark
|
|
|
|
@benchmark.register
|
|
def my_benchmark(state):
|
|
... # Code executed outside `while` loop is not timed.
|
|
|
|
while state:
|
|
... # Code executed within `while` loop is timed.
|
|
|
|
if __name__ == '__main__':
|
|
benchmark.main()
|
|
"""
|
|
|
|
import atexit
|
|
|
|
from absl import app
|
|
|
|
from google_benchmark import _benchmark
|
|
from google_benchmark._benchmark import (
|
|
Counter as Counter,
|
|
State as State,
|
|
kMicrosecond as kMicrosecond,
|
|
kMillisecond as kMillisecond,
|
|
kNanosecond as kNanosecond,
|
|
kSecond as kSecond,
|
|
o1 as o1,
|
|
oAuto as oAuto,
|
|
oLambda as oLambda,
|
|
oLogN as oLogN,
|
|
oN as oN,
|
|
oNCubed as oNCubed,
|
|
oNLogN as oNLogN,
|
|
oNone as oNone,
|
|
oNSquared as oNSquared,
|
|
)
|
|
|
|
__version__ = "1.9.0"
|
|
|
|
|
|
class __OptionMaker:
|
|
"""A stateless class to collect benchmark options.
|
|
|
|
Collect all decorator calls like @option.range(start=0, limit=1<<5).
|
|
"""
|
|
|
|
class Options:
|
|
"""Pure data class to store options calls, along with the benchmarked function."""
|
|
|
|
def __init__(self, func):
|
|
self.func = func
|
|
self.builder_calls = []
|
|
|
|
@classmethod
|
|
def make(cls, func_or_options):
|
|
"""Make Options from Options or the benchmarked function."""
|
|
if isinstance(func_or_options, cls.Options):
|
|
return func_or_options
|
|
return cls.Options(func_or_options)
|
|
|
|
def __getattr__(self, builder_name):
|
|
"""Append option call in the Options."""
|
|
|
|
# The function that get returned on @option.range(start=0, limit=1<<5).
|
|
def __builder_method(*args, **kwargs):
|
|
# The decorator that get called, either with the benchmared function
|
|
# or the previous Options
|
|
def __decorator(func_or_options):
|
|
options = self.make(func_or_options)
|
|
options.builder_calls.append((builder_name, args, kwargs))
|
|
# The decorator returns Options so it is not technically a decorator
|
|
# and needs a final call to @register
|
|
return options
|
|
|
|
return __decorator
|
|
|
|
return __builder_method
|
|
|
|
|
|
# Alias for nicer API.
|
|
# We have to instantiate an object, even if stateless, to be able to use __getattr__
|
|
# on option.range
|
|
option = __OptionMaker()
|
|
|
|
|
|
def register(undefined=None, *, name=None):
|
|
"""Register function for benchmarking."""
|
|
if undefined is None:
|
|
# Decorator is called without parenthesis so we return a decorator
|
|
return lambda f: register(f, name=name)
|
|
|
|
# We have either the function to benchmark (simple case) or an instance of Options
|
|
# (@option._ case).
|
|
options = __OptionMaker.make(undefined)
|
|
|
|
if name is None:
|
|
name = options.func.__name__
|
|
|
|
# We register the benchmark and reproduce all the @option._ calls onto the
|
|
# benchmark builder pattern
|
|
benchmark = _benchmark.RegisterBenchmark(name, options.func)
|
|
for name, args, kwargs in options.builder_calls[::-1]:
|
|
getattr(benchmark, name)(*args, **kwargs)
|
|
|
|
# return the benchmarked function because the decorator does not modify it
|
|
return options.func
|
|
|
|
|
|
def _flags_parser(argv):
|
|
argv = _benchmark.Initialize(argv)
|
|
return app.parse_flags_with_usage(argv)
|
|
|
|
|
|
def _run_benchmarks(argv):
|
|
if len(argv) > 1:
|
|
raise app.UsageError("Too many command-line arguments.")
|
|
return _benchmark.RunSpecifiedBenchmarks()
|
|
|
|
|
|
def main(argv=None):
|
|
return app.run(_run_benchmarks, argv=argv, flags_parser=_flags_parser)
|
|
|
|
|
|
# Methods for use with custom main function.
|
|
initialize = _benchmark.Initialize
|
|
run_benchmarks = _benchmark.RunSpecifiedBenchmarks
|
|
atexit.register(_benchmark.ClearRegisteredBenchmarks)
|