#include #include #include #include static unsigned int startTime= 0; static unsigned int timespan = 0; void Timer_Start(void) { startTime = clock(); } unsigned int Timer_Stop(void) { timespan = abs(clock() - startTime); return timespan; } void Timer_Output(void) { static const char * units[] = {"m", "s", "ms", "us"}; float seconds = (float)timespan / CLOCKS_PER_SEC; int unitIndex = 0; if (seconds <= 60) { for (unitIndex = 1; seconds < 1; unitIndex++) { seconds *= 1000; if (unitIndex == 3) break; } } else { seconds /= 60; } printf("---------------------------\nTime elapsed: %u%s\n\n", (unsigned int) seconds, units[unitIndex]); } void Timer_StopAndOutput(void) { Timer_Stop(); Timer_Output(); }