summaryrefslogtreecommitdiffstats
path: root/t/test_perf.c
blob: c729c4b964728199dedc32dde9521f9f8116d3a5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
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;
  const char *fls;

  ul_openlog ("umberlog/test_perf_simple", 0, LOG_LOCAL0);
  ul_set_log_flags (flags);

  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);

  ul_closelog ();

  dt = ts_diff (st, et);

  if (flags & LOG_UL_NOIMPLICIT)
    fls = "no-implicit";
  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_NOIMPLICIT, 100000);
  test_perf_simple (LOG_UL_NOIMPLICIT, 1000000);

  test_perf_simple (LOG_UL_NOTIME, 100000);
  test_perf_simple (LOG_UL_NOTIME, 1000000);

  return 0;
}