[SOLVED] C++ simplest way to measure elapsed time in constructors?

We are benchmarking some slow loading constructors, which includes objects being constructed in the editor details panel and while the Editor is starting up.

What’s the easiest way to measure time elapsed from one point to another in C++ without GetWorld() timer access and before BeginPlay()?

have you seen the ctime functions built into c/c++ I think. I have used them in the past many times without much trouble (many functions to get exact time in seconds, milliseconds).

I can’t remember exactly how to do it, but basically you make a variable which holds the start time and one for the end time and subtract the two to get the answer

FYI the simplest method is “FPlatformTime::Seconds()”. Requires no includes and works everywhere.

// start timer
double startSeconds = FPlatformTime::Seconds();
​
// DO A BUNCH OF STUFF

// print time elapsed
double secondsElapsed = FPlatformTime::Seconds() - startSeconds;
LOG("Time elapsed: %f seconds",  secondsElapsed);

3 Likes