-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest-helper.cpp
40 lines (31 loc) · 1.09 KB
/
test-helper.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
#include "test-helper.h"
#include "deserialize/deserializer.h"
#include <iomanip>
#include <iostream>
#include <memory>
node_ptr node_from_file(std::string const& filename) {
std::string str;
auto const readTime = timed([&] {
std::stringstream ss;
std::ifstream fs;
fs.open(filename);
ss << fs.rdbuf();
str = ss.str();
});
auto data = std::shared_ptr<Builder>{};
auto const parseJson = timed([&] { data = Parser::fromJson(str); });
auto nodePtr = node_ptr{};
auto const parseSlice =
timed([&] { nodePtr = node::from_slice(data->slice()); });
auto const readTime_s =
std::chrono::duration_cast<std::chrono::duration<double>>(readTime).count();
auto const jsonTime_s =
std::chrono::duration_cast<std::chrono::duration<double>>(parseJson).count();
auto const sliceTime_s =
std::chrono::duration_cast<std::chrono::duration<double>>(parseSlice).count();
std::cout << "Read file: " << readTime_s << "s, "
<< "parse json: " << jsonTime_s << "s, "
<< "parse slice: " << sliceTime_s << "s"
<< "\n";
return nodePtr;
}