-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
51 lines (43 loc) · 1.51 KB
/
main.cpp
File metadata and controls
51 lines (43 loc) · 1.51 KB
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
#include <iostream>
#include "json/json.hpp"
#include <fstream>
#include <chrono>
using namespace std;
using namespace json;
void doProcess(const string& fileName,double &avgParseTime);
int main(){
double avgParseTime = 0;
std::string fileName;
cin >> fileName;
cout << endl << endl;
cout << "First Test:\n";
doProcess(fileName,avgParseTime);
cout << "End First Test.\n\n";
avgParseTime = 0;
int times = 10;
for(int i = 0;i < times;++i)
doProcess(fileName,avgParseTime);
cout << endl << endl << avgParseTime/times << "ms";
return 0;
}
void doProcess(const string& fileName,double &avgParseTime){
double total = 0;
auto start = chrono::high_resolution_clock::now();
ifstream jsonFile{fileName};
string json,temp;
while(getline(jsonFile,temp)){
json += temp;
}
temp.clear();
auto diff = chrono::high_resolution_clock::now() - start;
total += chrono::duration<double, milli>(diff).count();
cout << "Reading " << fileName << ":\t" << chrono::duration<double, milli>(diff).count() << "ms\n";
start = chrono::high_resolution_clock::now();
//JSONObject jsonObject{json};
JSONArray jsonArray{json};
diff = chrono::high_resolution_clock::now() - start;
avgParseTime += chrono::duration<double, milli>(diff).count();
total += chrono::duration<double, milli>(diff).count();
cout << "Parsing:\t\t\t\t\t" << chrono::duration<double, milli>(diff).count() << "ms\n";
cout << "Total:\t\t\t\t\t\t" << total << "ms\n\n\n";
}