Comments (5)
This would have to fundamentally change the API I think. Currently, we just use macros to register user-defined static methods. With fixtures, we may have to change to the googletest model of defining classes from benchmarks.
Unless... Perhaps a 'fixture' can inherit from benchmark::State
and be passed to the benchmark instead of the state. Ie, you'd have something like:
static void BM_Basic(benchmark::State& state) {
while (state.KeepRunning()) {
...
}
}
BENCHMARK(BM_basic);
class MyState : public benchmark::State {
protected:
MyState() : _count(0) {}
~MyState() final {
std::stringstream ss;
ss << _count;
SetLabel(ss.str());
}
int _count;
};
static void BM_Fixture(MyState& state) {
while (state.KeepRunning()) {
...
++_count;
}
}
BENCHMARK_F(MyState, BM_Fixture);
We still need a second version of all the top-level registration macros that take a fixture, and we'd want to check that the given fixture is-a state. This will also require more templating on State...
What do you think, @EricWF?
from benchmark.
That makes sense to me for the most part. I agree that we shouldn't need to break the current API.
However I don't know if we should use the constructor/destructer for initialization/destruction. Since the fixture classes will likely have a static lifetime. I also don't know how your given example of BM_Fixture
would have _count
in scope.
from benchmark.
_count
isn't in scope - that was a bug :P
Why would the fixture classes have static lifetime? RunInThread
would need to create the state on the heap as a pointer using the correct fixture type (instead of on the stack as it is now) but it would have the same per-run lifetime. no?
from benchmark.
Hmm, Perhaps I'm not understanding what your fully suggesting. Could you explain further how you see these fixture classes working?
from benchmark.
I've tooled around and can't find a syntax i like. I was hoping to have either Stat
e be subclassed (but registering and instantiating that correctly is hard) so then I tried to have State
contain an 'inner state' of some user-defined type, but that was equally disruptive.
It's possible now for users to create an object with static lifetime and call methods on it outside the KeepRunning
loop so it's not a very high priority to implement.
My ideal would be that the user defines a type that they pass in through registration and an instance of that type lives for the lifetime of a benchmark run.
from benchmark.
Related Issues (20)
- [BUG] Missing `\n` at the End of Console Output HOT 2
- [FR] Enforce CMake to find PFM or fail when `BENCHMARK_ENABLE_LIBPFM` is `ON` HOT 2
- [BUG] QNX compilation failure on v1.8.3. Patch suggestion. HOT 2
- [BUG] mismatch of macro name for cmake
- [FR] Define HOST_NAME_MAX for z/OS HOT 1
- [FR] Add z/OS case to ThreadCPUUsage to avoid error HOT 1
- [BUG] fail to import gbench into compare.py with bazel and python3.12
- [FR] Large File Support HOT 5
- [FR] Support Win32 on Windows HOT 1
- [BUG] Console created through AllocConsole does not receive colored output HOT 3
- [BUG] Result of run with --benchmark_list_tests=true may not show on console
- [FR] JSON AoS<->SoA redesign HOT 6
- Migrate to bzlmod HOT 9
- [BUG] 1.8.3: build fails with gcc 14.x HOT 4
- [FR] Add `CMake` option to disable `benchmark_main` target HOT 2
- [BUG] Weird behavior of bytes_per_second and items_per_second HOT 8
- [FR] cp312 release on pypi
- [BUG] Reported iterations per run when using repetitions always the same value? HOT 3
- [BUG] With NDEBUG, early-returning without SkipWithError leads to indefinite retries HOT 5
- Complexity calculation does not work for manual timing
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from benchmark.