Closed mbauman closed 9 years ago
Finally have some time to finish this package. I think this approach is reasonable and I'm willing to accept the cost of a function call to minimize weird effects elsewhere. Would be great to get this rebased whenever you have some time.
The one thing I'm worried about is that this seems to remove the possibility of benchmarking expressions that depend upon variables that have to be setup in the setup expression, because those variables are now globals being accessed by the inner function.
Or is that concern not relevant for a reason that's not obvious to me?
Ah, no, you're right. I didn't think about the setup expr — I'm not sure how to best address that. In fact, I think benchmarks that require variables from a setup expr will now fail (since they aren't global). I'm not sure how to best deal with that.
One possible alternative would be to only permit benchmarking single functions with the simple @benchmark
macro, and then evaluate all arguments to that function as "setup". This is similar to what @Yuyichao proposed in https://github.com/johnmyleswhite/Benchmarks.jl/issues/16#issuecomment-136337077. The constant binding/literal vs mutable binding heuristic I use here is a little subtle.
I feel like getting this totally right is slightly above my current level of understanding of the compiler. I might try to start an e-mail thread with some core compiler folks to figure this out.
Positive effects:
Negative effects:
Demo. Minimum time is function call:
And the pathological cases over at #16 are fixed: