mirror of https://github.com/google/benchmark.git
Expose `SkipWithError` in Python bindings. (#968)
This commit is contained in:
parent
9284e90f28
commit
6746c65bcf
|
@ -42,6 +42,7 @@ PYBIND11_MODULE(_benchmark, m) {
|
|||
|
||||
py::class_<benchmark::State>(m, "State")
|
||||
.def("__bool__", &benchmark::State::KeepRunning)
|
||||
.def_property_readonly("keep_running", &benchmark::State::KeepRunning);
|
||||
.def_property_readonly("keep_running", &benchmark::State::KeepRunning)
|
||||
.def("skip_with_error", &benchmark::State::SkipWithError);
|
||||
};
|
||||
} // namespace
|
||||
|
|
|
@ -28,5 +28,14 @@ def sum_million(state):
|
|||
sum(range(1_000_000))
|
||||
|
||||
|
||||
@benchmark.register
|
||||
def skipped(state):
|
||||
if True: # Test some predicate here.
|
||||
state.skip_with_error('some error')
|
||||
return # NOTE: You must explicitly return, or benchmark will continue.
|
||||
|
||||
... # Benchmark code would be here.
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
benchmark.main()
|
||||
|
|
Loading…
Reference in New Issue