progs/perf: add human-readable float formatter

This commit is contained in:
Keith Whitwell
2009-09-21 15:51:26 +01:00
parent d17af7d1e1
commit ed63bd62d8
2 changed files with 20 additions and 0 deletions
+18
View File
@@ -113,3 +113,21 @@ PerfMeasureRate(PerfRateFunc f)
}
/* Note static buffer, can only use once per printf.
*/
const char *
PerfHumanFloat( double d )
{
static char buf[80];
if (d > 1000000000.0)
snprintf(buf, sizeof(buf), "%.1f billion", d / 1000000000.0);
else if (d > 1000000.0)
snprintf(buf, sizeof(buf), "%.1f million", d / 1000000.0);
else if (d > 1000.0)
snprintf(buf, sizeof(buf), "%.1f thousand", d / 1000.0);
else
snprintf(buf, sizeof(buf), "%.1f", d);
return buf;
}
+2
View File
@@ -30,6 +30,8 @@ typedef void (*PerfRateFunc)(unsigned count);
extern double
PerfMeasureRate(PerfRateFunc f);
const char *
PerfHumanFloat( double d );
extern void
perf_printf(const char *format, ...);