-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprofiler.cpp
74 lines (53 loc) · 1.43 KB
/
profiler.cpp
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
#define JSKOROST_IMPLEMENTATION
#include "jskorost.h"
#include <time.h>
#include "rapidjson/include/rapidjson/document.h"
#include "rapidjson/include/rapidjson/writer.h"
#include "rapidjson/include/rapidjson/stringbuffer.h"
int main(int argc, char **argv)
{
if (argc < 2) {
fprintf(stderr, "Expected a filename\n");
return 1;
}
const char *const filename = argv[1];
FILE *f = fopen(filename, "rb");
if (!f) {
fprintf(stderr, "Couldn't open file '%s'\n", filename);
return 1;
}
fseek(f, 0, SEEK_END);
const long length = ftell(f);
fseek(f, 0, SEEK_SET);
char *buffer = (char *)malloc(length);
if (!buffer) {
fprintf(stderr, "Can't allocate file buffer\n");
return 1;
}
fread(buffer, 1, length, f);
fclose(f);
jsk_heap *h = jsk_heap_new(NULL);
clock_t start, end;
double time_used;
jsk_result res;
std::string s(buffer, length);
const char *cs = s.c_str();
start = clock();
rapidjson::Document d;
d.Parse(cs);
end = clock();
time_used = ((double)(end - start)) / CLOCKS_PER_SEC;
printf("RapidJSON successfully parsed: %f\n", time_used);
start = clock();
res = jsk_parse(h, buffer, length);
if (res.status != JSK_OK) {
fprintf(stderr, "JSkorost failed to parse JSON: %s\n", res.data.error);
return 1;
}
end = clock();
jsk_heap_free(h);
time_used = ((double)(end - start)) / CLOCKS_PER_SEC;
printf("JSkorost successfully parsed: %f (%f/sec)\n", time_used,
length / time_used);
return 0;
}