diff options
author | Gergely Nagy <algernon@balabit.hu> | 2012-04-13 10:42:29 +0200 |
---|---|---|
committer | Gergely Nagy <algernon@balabit.hu> | 2012-04-13 10:42:29 +0200 |
commit | 63fcf21f9a9f616880dfb9c7174b8694423a7f75 (patch) | |
tree | dd4adbb141c456bf009faf2d2f5781546173885c /t/test_perf.c | |
parent | 0e51e1024a85a6fb3a7b9e24de0f3817ccf58e0f (diff) | |
download | libumberlog-63fcf21f9a9f616880dfb9c7174b8694423a7f75.tar.gz libumberlog-63fcf21f9a9f616880dfb9c7174b8694423a7f75.tar.xz libumberlog-63fcf21f9a9f616880dfb9c7174b8694423a7f75.zip |
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 <algernon@balabit.hu>
Diffstat (limited to 't/test_perf.c')
-rw-r--r-- | t/test_perf.c | 73 |
1 files changed, 73 insertions, 0 deletions
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 <stdio.h> +#include <stdlib.h> +#include <time.h> + +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; +} |