File: testlib.c

package info (click to toggle)
dateutils 0.4.3-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 4,924 kB
  • sloc: ansic: 22,097; makefile: 1,666; yacc: 198; sh: 168; lex: 108
file content (74 lines) | stat: -rw-r--r-- 1,403 bytes parent folder | download | duplicates (4)
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
74
/* library tester */
#include <unistd.h>
#include <stdio.h>
#include <time.h>
#include "date-core.h"

static const char test_ymd[] = "2001-02-03";
static const char test_ybd[] = "2001-Feb-03";

static void __attribute__((unused))
orig_strptime_perf(size_t nruns)
{
	for (size_t i = 0; i < nruns; i++) {
		struct tm tm;
		strptime(test_ymd, "%Y-%m-%d", &tm);
	}
	return;
}

static void __attribute__((unused))
test_strpd(size_t nruns)
{
	struct dt_d_s s;

	for (size_t i = 0; i < nruns; i++) {
		if ((s = dt_strpd(test_ymd, "%F", NULL)).u == 0) {
			break;
		}
	}
	if ((s = dt_strpd(test_ymd, "%F", NULL)).typ) {
		char buf[256];
		dt_strfd(buf, sizeof(buf), "%F %a %A %b %B\n", s);
		fputs(buf, stdout);
	}
	if ((s = dt_strpd(test_ybd, "%Y-%b-%d", NULL)).typ) {
		char buf[256];
		dt_strfd(buf, sizeof(buf), "%F %a %A %b %B\n", s);
		fputs(buf, stdout);
	}
	return;
}

static void __attribute__((unused))
test_date(size_t nruns)
{
	struct dt_d_s s = {{0}};
	char buf[256];

	for (size_t i = 0; i < nruns; i++) {
		if ((s = dt_date(DT_YMCW)).u == 0) {
			break;
		}
	}
	dt_strfd(buf, sizeof(buf), "%Y-%m-%c-%w\n", s);
	fputs(buf, stdout);
	return;
}


int
main(int argc __attribute__((unused)), char *argv[] __attribute__((unused)))
{
	const size_t nruns = 10000000;
#if 0
	orig_strptime_perf(nruns);
#elif 0
	test_strpd(nruns);
#elif 1
	test_date(nruns);
#endif
	return 0;
}

/* testlib.c ends here */