How you easily measure the time it takes a block of C++ code to run?

Thank you for the clear explanation, and for confirming this is the way to go. However, I had tried this approach before, and couldn’t get it to work. And still can’t. I followed your instructions exactly. I get a table in the viewport showing the names of my stats. When I run the game, I get some numbers in the table for less than a second, then they vanish. The ‘call count’ never goes above zero.

So my next question is, does this method only work on functions that get called repeatedly in the game loop, in the same session? Because the functions I’m interested in only occur once, at initialization time. I was hoping this would keep an average across runs.

I should just write my own profiling functions and be done with it. I’ve been on this for days.