-
-
Notifications
You must be signed in to change notification settings - Fork 124
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
@BeforeMethod()
does not get called before each call?
#896
Comments
…d `ServiceManager` instance Ref: phpbench/phpbench#304 Ref: phpbench/phpbench#896
The problem (as you know) is that then it introduces the call to a
Trying to reset the state in a way that didn't end up reducing the percentage of time which is executing the code you are benchmarking is hard. Possible solutions though:
|
Shouldn't it be before measurements start? In pseudo code:
|
i don't think so - because it further contaminates the loop. think of your example is similar to running PHPBench with |
So the correct workaround would be to run everything with What about warmup laps? Does |
Not really -the resolution would be too low - I would assume you are measuring at a microsecond resolution, that is thrown out by the calls to It would be interesting to see if Would be interesting to try both.
phpbench/lib/Executor/Benchmark/template/remote.template Lines 34 to 37 in 722572f
Worth thinking if you want to do heavy things like booting a DI container or preparing fixtures before every revolution. I think what we are talking could be a new feature rather than changing |
PHPUnit has the PHPUnit also lets you run bootstrapping logic before any tests are ran, so you can set up the application the way that you need only once at the beginning of the tests. It seems like PHPBench is missing that feature, to be able to set up a benchmark before each run. Except in this case including the setup logic inside the benchmark methods themselves also has additional drawbacks that wouldn't be the case with PHPUnit. Although maybe I'm misunderstanding the difference between revs and iterations and the solution really is to just have one rev with many iterations. |
Yeah, the reason why I haven't closed this issue yet is that:
Right now, I think most bench suites that I have (which use If foreach ($repetition as $i) {
reset_stuff();
start_measuring();
run_benchmark_method();
stop_measuring();
} |
My main concern (which may or may not be valid) is that it affects the information content of the sample.
The subject is reset via. BeforeMethods before it starts the revolutions (for loop), and the result is the Iteration. You can run the loop with But in general, need to do some research to see what can be done or how correct my assumptions are. |
Agreed, but right now, we're not measuring anything valuable either :D
That would then lead to things like autoloading overhead (and accidental measurement thereof), no? |
Depends if you have state or not ?
|
There's always some degree of state, so re-creating (or re-using, which is where I would design two separate benchmarks to see the difference) the SUT is vital. |
Specifically, if you believe it is possible to achieve precise measurements as per current state, I would need some guidance on boesing/laminas-servicemanager@d6e7fe4 - perhaps this can be reduced to a documentation issue then? |
to be honest i don't know. the original reasoning is that the grain is a microsecond, which is pretty useless at the current execution template won't remove the i'll need to investigate and experiment (and this is pretty much next priority) |
You don't need to make this a priority: at this point, we're just pillaging this issue :D It's just a thing to be aware of, if you are tinkering with the design of |
well, it fits into general improvements around execution etc, and I genuinely want to be able to answer these questions 😅 |
so I did an experiment: outcome is that At that point running with |
I was working on laminas/laminas-servicemanager#93 today, and noticed that we still have the codebase sprinkled with blocks referencing #304
In fact, #304 has been closed as "old", but still applies today.
My assumption was that
@BeforeMethods
would be called before each call to said bench method: doesn't seem to be the case, and that leads to benchmarking warmed up caches too, which is a problem (especially if we're benchmarking said warmup).In following example, I would expect 100 calls to
mySetup()
, but only10
are occurring:What's the best way forward here? Is a change in
@BeforeMethods
viable? It would change the benchmark results for bench suites I've worked on so far, massively, but it would lead to more honest results.The text was updated successfully, but these errors were encountered: