-
Notifications
You must be signed in to change notification settings - Fork 0
/
json_example.cpp
56 lines (47 loc) · 1.24 KB
/
json_example.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
#include <iostream>
#include <fstream>
#include <chrono>
#include "gjson.h"
#include "nl_json.hpp"
void RunNl(char * filename)
{
auto old = std::chrono::system_clock::now();
std::ifstream is(filename);
auto data = nlohmann::json::parse(is);
std::cout << "(nlohmann)Duration:" << (std::chrono::system_clock::now() - old).count() / 1000000.0 <<" ms" << std::endl;
}
void RunMy(char* filename)
{
auto old = std::chrono::system_clock::now();
std::ifstream is(filename);
//std::ifstream is("../sample/large-file.json");
if(is)
{
auto pJson = gjson::ParseJson(is);
if(pJson)
{
//pJson->print(std::wcout);
}
else
{
std::cout << "Parse json failed" << std::endl;
}
}
else
{
std::cout << "Failed to open file " << filename << std::endl;
}
std::cout << "(My)Duration:" << (std::chrono::system_clock::now() - old).count() / 1000000.0 <<" ms" << std::endl;
}
int main(int argc, char*argv[])
{
std::cout << "json_example <filename>" << std::endl;
if(argc < 2)
{
std::cout << "usage: json_example <filename>" << std::endl;
return 1;
}
//RunNl(argv[1]);
RunMy(argv[1]);
return 0;
}