-
Notifications
You must be signed in to change notification settings - Fork 84
Expand file tree
/
Copy pathtest_speed.c
More file actions
54 lines (45 loc) · 714 Bytes
/
test_speed.c
File metadata and controls
54 lines (45 loc) · 714 Bytes
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
#include <stdio.h>
#include <stdlib.h>
#include "json_parser.h"
#define BUFSIZE (64 * 1024 * 1024)
int main(int argc, char *argv[])
{
static char buf[BUFSIZE];
size_t n;
if (argc != 2)
{
fprintf(stderr, "USAGE: %s <repeat times>\n", argv[0]);
exit(1);
}
n = fread(buf, 1, BUFSIZE, stdin);
if (n > 0)
{
if (n == BUFSIZE)
{
fprintf(stderr, "File too large.\n");
exit(1);
}
buf[n] = '\0';
}
else
{
perror("fread");
exit(1);
}
int rep = atoi(argv[1]);
int i;
for (i = 0; i < rep; i++)
{
json_value_t *val = json_value_parse(buf);
if (val)
{
json_value_destroy(val);
}
else
{
fprintf(stderr, "Invalid JSON document.\n");
exit(1);
}
}
return 0;
}