-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_file.cpp
63 lines (50 loc) · 1.51 KB
/
test_file.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
//
// Created by BangshengXie on 04/06/2017.
//
#include "test_file.h"
#include "BubbleJSON/BubbleJson.h"
#include <iostream>
#include <fstream>
#include <tuple>
#include <chrono>
using namespace std;
using namespace bubbleJson;
void TestParseFromFile()
{
tuple<ParseResults, BubbleValue*> result;
BubbleValue *value;
BubbleJson bubbleJson;
//read file
ifstream file;
file.open("test.json");
if (!file)
{
cout<<"file is not found!"<<endl;
return;
}
string json;
string tmp;
while (getline(file,tmp))
{
json += tmp;
};
file.close();
//parse
auto start = chrono::high_resolution_clock::now();
result = bubbleJson.Parse(json);
value = get<1>(result);
auto end = chrono::high_resolution_clock::now();
auto parseElapsed = chrono::duration_cast<chrono::milliseconds>(end - start);
//stringify
start = chrono::high_resolution_clock::now();
auto stringifyResult = bubbleJson.Stringify(value, StringifyType_Beauty);
end = chrono::high_resolution_clock::now();
auto stringifyElapsed = chrono::duration_cast<chrono::milliseconds>(end - start);
//check result
if(get<0>(result) != ParseResult_Ok)
fprintf(stderr, "%s:%d: expect: 0 actual: %d", __FILE__, __LINE__, get<0>(result));
cout<<"parse from file elapsed time: "<<parseElapsed.count()<<" ms"<<endl;
cout<<"stringify from file elapsed time: "<<stringifyElapsed.count()<<" ms"<<endl;
delete value;
free (get<0>(stringifyResult));
}