summaryrefslogtreecommitdiff
path: root/progs/perf/common.c
diff options
context:
space:
mode:
Diffstat (limited to 'progs/perf/common.c')
-rw-r--r--progs/perf/common.c50
1 files changed, 47 insertions, 3 deletions
diff --git a/progs/perf/common.c b/progs/perf/common.c
index a50fc11cca..b6489ef918 100644
--- a/progs/perf/common.c
+++ b/progs/perf/common.c
@@ -26,6 +26,32 @@
#include "common.h"
#include "glmain.h"
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdarg.h>
+
+#if defined(_MSC_VER)
+#define snprintf _snprintf
+#endif
+
+
+/* Need to add a fflush windows console with mingw, otherwise nothing
+ * shows up until program exit. May want to add logging here.
+ */
+void
+perf_printf(const char *format, ...)
+{
+ va_list ap;
+ va_start(ap, format);
+
+ fflush(stdout);
+ vfprintf(stdout, format, ap);
+ fflush(stdout);
+
+ va_end(ap);
+}
+
+
/**
* Run function 'f' for enough iterations to reach a steady state.
@@ -52,7 +78,7 @@ PerfMeasureRate(PerfRateFunc f)
subiters *= 2;
} while (t1 - t0 < 0.1 * minDuration);
}
- /*printf("initial subIters = %u\n", subiters);*/
+ /*perf_printf("initial subIters = %u\n", subiters);*/
while (1) {
const double t0 = PerfGetTime();
@@ -68,7 +94,7 @@ PerfMeasureRate(PerfRateFunc f)
rate = iters / (t1 - t0);
if (0)
- printf("prevRate %f rate %f ratio %f iters %u\n",
+ perf_printf("prevRate %f rate %f ratio %f iters %u\n",
prevRate, rate, rate/prevRate, iters);
/* Try and speed the search up by skipping a few steps:
@@ -86,8 +112,26 @@ PerfMeasureRate(PerfRateFunc f)
}
if (0)
- printf("%s returning iters %u rate %f\n", __FUNCTION__, subiters, rate);
+ perf_printf("%s returning iters %u rate %f\n", __FUNCTION__, subiters, rate);
return rate;
}
+/* 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;
+}