Long story short, I’m recoding a very CPU hungry app, going to restructure it in an entirely different way, and change alot of it’s inner workings. I was looking for a good way to compare old and new results.
Say I start by changing how function foo() works:
I want to have the program run for say, 60 seconds, and measure the % of CPU that function is using within the program’s total CPU usage. If it’s at a constant 25%, I want to know how much of those 25% is my function. Then I’ll test after changing code, and have two good indicators of whether I had a good improvement.
I’ve tried Very Sleepy but I can’t get access to the functions I wanted access to; they do not show. I want to be able to see the % usage of the function I CODED MYSELF that uses the library’s functions (SDL), yet it will only show me SDL Functions.
There are a few different ways, one of which is to simply add a high precision timer call at the start and end of the function. Depending on the number of calls to your function, you can either accumulate the time, e.g:
Or you can store the individual intervals, e.g.
Of course, if your calls to SDL are in the middle of your function, you need to one way or another discount that time.
Another method would be to measure the individual timing of several functions:
I’ve certainly used all of these functions, and as long-running as the functions are reasonably large, it shouldn’t add much overhead.
You can also measure several functions at once, e.g. if we want to have the WHOLE function, we could just add the enum “BIG_FUNC” to the enum list above, and do this: