summaryrefslogtreecommitdiffstats
path: root/web/server/h2o/libh2o/deps/klib/test/kstring_bench.c
blob: 82598e88cfe0f305a278da78d490ce9459c41d54 (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
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include "kstring.h"

#define N 10000000

int main()
{
	int i;
	clock_t t;
	kstring_t s, s2;
	srand48(11);
	s.l = s.m = 0; s.s = 0;
	t = clock();
	for (i = 0; i < N; ++i) {
		int x = lrand48();
		s.l = 0;
		kputw(x, &s);
	}
	fprintf(stderr, "kputw: %lf\n", (double)(clock() - t) / CLOCKS_PER_SEC);
	srand48(11);
	t = clock();
	for (i = 0; i < N; ++i) {
		int x = lrand48();
		s.l = 0;
		ksprintf(&s, "%d", x);
	}
	fprintf(stderr, "ksprintf: %lf\n", (double)(clock() - t) / CLOCKS_PER_SEC);

	srand48(11);
	s2.l = s2.m = 0; s2.s = 0;
	t = clock();
	for (i = 0; i < N; ++i) {
		int x = lrand48();
		s2.l = s.l = 0;
		kputw(x, &s2);
		kputs(s2.s, &s);
	}
	fprintf(stderr, "kputw+kputs: %lf\n", (double)(clock() - t) / CLOCKS_PER_SEC);
	srand48(11);
	t = clock();
	for (i = 0; i < N; ++i) {
		int x = lrand48();
		s2.l = s.l = 0;
		kputw(x, &s2);
		ksprintf(&s, "%s", s2.s);
	}
	fprintf(stderr, "kputw+ksprintf: %lf\n", (double)(clock() - t) / CLOCKS_PER_SEC);
	return 0;
}