That C code has become a bit prehistoric these days. I am not sure if timeb is portable either (though certainly with conditional compilation the prior snippet can be made to port on Windows and Linux for low 1ms resolution timer).
Here is STL C++ code for high resolution and portable code, requires no coding and mostly just ugly namespace declaration and templates.
Quote:
#include <chrono>
std::chrono::time_point<std::chrono::high_resolution_clock> start = std::chrono::high_resolution_clock::now();
//do things
std::chrono::duration<double, std::milli> elapsed = std::chrono::high_resolution_clock::now() - start;
printf("\nProcessing time %8.3f seconds\n", elapsed.count());
|