As far as I can tell, all the basic performance measurement tools operate by giving a macro an expression to evaluate. This seems odd to me, and I think I’m missing an understanding of why this is so. This question is a request for help filling that part in.
I want to measure the performance of some parts of my code and not others, for example profiling the numerical computation but not profiling writing the results to disk. So it seemed natural to have code that started timing and then stopped it. But that would require getting an initial state and then a terminal one.
By “profiling” I do not mean line-by-line performance info, just the total such as reported by @time
.
As far as I can tell, the documented interface doesn’t explain how to get the components (wall time, cpu time–I assume these are available somewhere, though maybe not with great precision–allocation counts and bytes, possibly gc time and compile time), and all the profiling stuff is oriented around things like @time
which must wrap the complete expression and then reports the results.
tic()
and toc()
once did something like what I’m thinking of, though maybe only for time, not memory. They were deprecated for reasons that are not obvious to me in the issue history. Some of the reasons given there and elsewhere seem to be that they could be misused, and some of the reasons (that they used global state) weren’t even true.
At least 2 packages seem to provide similar start/stop functionality, Timers and TickTock, and TimerOutputs may also provide tools to time chunks. I don’t know if any of them track anything other than time, however.
So there may be alternative that do what I want, and even if not, I can probably structure my code so that the things of interest are contained in a function call, so that @time
and friends will work. So my question isn’t “How do I do what I want?”. It’s more why is it so hard? Why is all the performance gathering information wrapped up in macros that require a single expression, and why isn’t a way to get the individual components directly (not use @timed
and pull out the results) discussed?