How to measure elapsed time in C++ Builder 6

Viewed 30

I would like to measure the elapsed time of a multimedia timer cycle. On the internet I have found the usage of , but it does not work in C++ Builder 6. The error message: [C++ Error] Thread_01.cpp(6): E2209 Unable to open include file 'chrono.h' What options do I have, to measure elapsed time with high precision.

1 Answers

I strongly suggest you upgrade to a newer compiler.

That said, <chrono> is a C++11 extension to the standard. Borland C++ Builder 6 does not support that standard, hence this approach is not feasible for you.

Depending on the accuracy you require, you can use something as simple as

time_t now = time(NULL);
//DoStuff
int elapsed = time(NULL) - start;

This will give you the elapsed time in seconds.

For something a little more precise (which takes more work), I suggest you look at the suggestions at using gettimeofday() equivalents on windows.

Related