File tree Expand file tree Collapse file tree 2 files changed +11
-1
lines changed
bindings/python/google_benchmark Expand file tree Collapse file tree 2 files changed +11
-1
lines changed Original file line number Diff line number Diff line change @@ -167,7 +167,15 @@ NB_MODULE(_benchmark, m) {
167167 .def_prop_rw (" items_processed" , &State::items_processed,
168168 &State::SetItemsProcessed)
169169 .def (" set_label" , &State::SetLabel)
170- .def (" range" , &State::range, nb::arg (" pos" ) = 0 )
170+ .def (
171+ " range" ,
172+ [](const State& state, std::size_t pos = 0 ) -> int64_t {
173+ if (pos < state.range_size ()) {
174+ return state.range (pos);
175+ }
176+ throw nb::index_error (" pos is out of range" );
177+ },
178+ nb::arg (" pos" ) = 0 )
171179 .def_prop_ro (" iterations" , &State::iterations)
172180 .def_prop_ro (" name" , &State::name)
173181 .def_rw (" counters" , &State::counters)
Original file line number Diff line number Diff line change @@ -956,6 +956,8 @@ class BENCHMARK_EXPORT BENCHMARK_INTERNAL_CACHELINE_ALIGNED State {
956956 BENCHMARK_ALWAYS_INLINE
957957 std::string name () const { return name_; }
958958
959+ size_t range_size () const { return range_.size (); }
960+
959961 private:
960962 // items we expect on the first cache line (ie 64 bytes of the struct)
961963 // When total_iterations_ is 0, KeepRunning() and friends will return false.
You can’t perform that action at this time.
0 commit comments