16 #ifndef _GLIBCXX_STRING
19 #ifndef _GLIBCXX_CSTDIO
22 #ifndef _GLIBCXX_CTIME
28 unsigned long loop_counter;
40 clock_t stopped_at = clock();
41 clock_t ticks = stopped_at-started_at;
42 double seconds = double(ticks)/CLOCKS_PER_SEC;
44 printf(
"Time for '%s': ticks=%lu (= %5.2f seconds)",
45 message.c_str(), ticks, seconds);
47 if (loop_counter > 0) {
48 if (loop_counter == 1) {
52 double lticks = double(ticks)/loop_counter;
53 double lseconds = lticks/CLOCKS_PER_SEC;
55 printf(
" %lu loops. Each took: ticks=%lu",
56 loop_counter, (clock_t)(lticks+0.5));
57 if (lseconds >= 0.01) {
58 printf(
" (= %5.2f seconds)", lseconds);
61 printf(
" (= %5.2f milliseconds)", lseconds/1000);
64 double loopsPerSecond = loop_counter/seconds;
65 printf(
" = %5.2f loops/second", loopsPerSecond);
77 #error perf_timer.h included twice
78 #endif // PERF_TIMER_H
return string(buffer, length)
PerfTimer(const std::string &message_)