mirror of https://github.com/jlizier/jidt
Improved ctimer to align printf outputs.
This commit is contained in:
parent
82c06abbeb
commit
3fb9632439
|
|
@ -2,6 +2,7 @@
|
|||
#include <stdio.h>
|
||||
#include <time.h>
|
||||
#include <sys/time.h>
|
||||
#include <string.h>
|
||||
|
||||
typedef struct CPerfTimer {
|
||||
struct timeval tv;
|
||||
|
|
@ -22,7 +23,13 @@ static inline void stopTimer(CPerfTimer pt) {
|
|||
struct timeval tv;
|
||||
gettimeofday(&tv, NULL);
|
||||
unsigned long us = 1000000 * tv.tv_sec + tv.tv_usec;
|
||||
printf("%s: %.3fms\n", pt.tag, (us - pt.us)/((double) 1000.0));
|
||||
if (strlen(pt.tag) < 50) {
|
||||
char buf[50] = " ";
|
||||
memcpy(buf, pt.tag, strlen(pt.tag));
|
||||
printf("%s: %.3fms\n", buf, (us - pt.us)/((double) 1000.0));
|
||||
} else {
|
||||
printf("%s: %.3fms\n", pt.tag, (us - pt.us)/((double) 1000.0));
|
||||
}
|
||||
#endif
|
||||
return;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue