summaryrefslogtreecommitdiff
path: root/main.c
blob: 846c8c9f0ec696d0c9da601c5f5e8b018da56592 (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
#include <u.h>
#include <libc.h>
#include <json.h>

enum {
	MB = 1024*1024
};

vlong t0, Δt;

void
usage(void)
{
	fprint(2, "usage: %s file\n", argv0);
	exits("usage");
}

void
main(int argc, char *argv[])
{
	JSON *j;
	char buf[8*MB];
	int fd;

	JSONfmtinstall();
	ARGBEGIN{
	default: usage();
	}ARGEND;
	if(argc != 1)
		usage();
	fd = open(argv[0], OREAD);
	if(fd < 0)
		sysfatal("open: %r");
	if(read(fd, buf, sizeof buf) <= 0)
		sysfatal("read: %r");
	t0 = nsec();
	j = jsonparse(buf);
	Δt = nsec()-t0;
	fprint(2, "jsonparse took %lldns\n", Δt);
	if(j == nil)
		sysfatal("jsonparse: %r");
	t0 = nsec();
	print("%J\n", j);
	Δt = nsec()-t0;
	fprint(2, "jsonfmt took %lldns\n", Δt);
	exits(0);
}