forked from Cheedoong/xml2json
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.cpp
More file actions
71 lines (63 loc) · 1.7 KB
/
Copy pathtest.cpp
File metadata and controls
71 lines (63 loc) · 1.7 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#include <iostream>
#include <vector>
#include <map>
#include <string>
#include <sstream>
#include <fstream>
#include <sys/time.h>
#include <time.h>
#include "xml2json.hpp"
using namespace std;
int64_t getCurrentTime()
{
struct timeval tval;
gettimeofday(&tval, NULL);
return tval.tv_sec * 1000000LL + tval.tv_usec;
}
int main(int argc, const char *argv[])
{
//file<> fdoc("track_orig.xml");
string xml_str, json_str;
ifstream inf;
ofstream outf;
ostringstream oss;
char BOM[4] = {(char)0xEF, (char)0xBB, (char)0xBF, '\0'}; /*BOM String*/
int64_t start_time, end_time;
inf.open("test_track_1.xml");
outf.open("test_track_1.js.txt");
oss.str("");
oss << inf.rdbuf();
xml_str = oss.str();
inf.close();
start_time = getCurrentTime();
json_str = xml2json(xml_str.c_str());
end_time = getCurrentTime();
cout << "time1: " << end_time - start_time << endl;
outf << BOM << json_str;
outf.close();
inf.open("test_track_2.xml");
outf.open("test_track_2.js.txt");
oss.str("");
oss << inf.rdbuf();
xml_str = oss.str();
inf.close();
start_time = getCurrentTime();
json_str = xml2json(xml_str.c_str());
end_time = getCurrentTime();
cout << "time2: " << end_time - start_time << endl;
outf << BOM << json_str;
outf.close();
inf.open("test_track_3.xml");
outf.open("test_track_3.js.txt");
oss.str("");
oss << inf.rdbuf();
xml_str = oss.str();
inf.close();
start_time = getCurrentTime();
json_str = xml2json(xml_str.c_str());
end_time = getCurrentTime();
cout << "time3: " << end_time - start_time << endl;
outf << BOM << json_str;
outf.close();
return 0;
}