From 63fcf21f9a9f616880dfb9c7174b8694423a7f75 Mon Sep 17 00:00:00 2001 From: Gergely Nagy Date: Fri, 13 Apr 2012 10:42:29 +0200 Subject: t/: Add a new performance test. The new test case always succeeds, it's purpose is to echo the performance results. Signed-off-by: Gergely Nagy --- t/test_perf.c | 73 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 t/test_perf.c (limited to 't/test_perf.c') diff --git a/t/test_perf.c b/t/test_perf.c new file mode 100644 index 0000000..9e28b20 --- /dev/null +++ b/t/test_perf.c @@ -0,0 +1,73 @@ +#define _GNU_SOURCE 1 + +#include "umberlog.h" +#include +#include +#include + +static inline struct timespec +ts_diff (struct timespec start, struct timespec end) +{ + struct timespec temp; + if ((end.tv_nsec - start.tv_nsec) < 0) + { + temp.tv_sec = end.tv_sec - start.tv_sec - 1; + temp.tv_nsec = 1000000000 + end.tv_nsec - start.tv_nsec; + } + else + { + temp.tv_sec = end.tv_sec - start.tv_sec; + temp.tv_nsec = end.tv_nsec - start.tv_nsec; + } + return temp; +} + +static inline void +test_perf_simple (int flags, unsigned long cnt) +{ + char *msg; + unsigned long i; + struct timespec st, et, dt; + long nsec; + const char *fls; + + openlog ("umberlog/test_perf_simple", flags, LOG_LOCAL0); + + clock_gettime (CLOCK_MONOTONIC, &st); + for (i = 0; i < cnt; i++) + { + msg = ul_format (LOG_DEBUG, "hello, I'm %s!", __FUNCTION__, NULL); + free (msg); + } + clock_gettime (CLOCK_MONOTONIC, &et); + + closelog (); + + dt = ts_diff (st, et); + + if (flags & LOG_UL_NODISCOVER) + fls = "no-discover"; + else if (flags & LOG_UL_NOTIME) + fls = "no-time"; + else + fls = "discover"; + + printf ("# test_perf_simple(%s, %lu): %lu.%lus\n", + fls, cnt, + dt.tv_sec, dt.tv_nsec); +} + +int +main (void) +{ + test_perf_simple (0, 100000); + test_perf_simple (0, 1000000); + + test_perf_simple (LOG_UL_NODISCOVER, 100000); + test_perf_simple (LOG_UL_NODISCOVER, 1000000); + + test_perf_simple (LOG_UL_NOTIME, 100000); + test_perf_simple (LOG_UL_NOTIME, 1000000); + + return 0; +} -- cgit