Improved ctimer to align printf outputs.

This commit is contained in:
Pedro Martinez Mediano 2017-05-25 01:06:04 +10:00
parent 82c06abbeb
commit 3fb9632439
1 changed files with 8 additions and 1 deletions

View File

@ -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;
}