Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- void Benchmark() {
- const auto start = std::chrono::steady_clock::now();
- Array arr;
- arr.reserve(1'000);
- for (int i = 0; i < 2; ++i) {
- arr.emplace_back(Dict{
- {"int"s, 42},
- {"double"s, 42.1},
- {"null"s, nullptr},
- {"string"s, "hello"s},
- {"array"s, Array{1, 2, 3}},
- {"bool"s, true},
- {"map"s, Dict{{"key"s, "value"s}}},
- });
- }
- std::stringstream strm;
- json::Print(Document{arr}, strm);
- const auto doc = json::Load(strm);
- assert(doc.GetRoot() == arr);
- const auto duration = std::chrono::steady_clock::now() - start;
- std::cout << std::chrono::duration_cast<std::chrono::milliseconds>(duration).count() << "ms"sv
- << std::endl;
- Print(Document{arr}, std::cout);
- }
- [
- {
- "array": [
- 1,
- 2,
- 3
- ],
- "bool": true,
- "double": 42.1,
- "int": 42,
- "map": {
- "key": "value"
- },
- "null": null,
- "string": "hello"
- },
- {
- "array": [
- 1,
- 2,
- 3
- ],
- "bool": true,
- "double": 42.1,
- "int": 42,
- "map": {
- "key": "value"
- },
- "null": null,
- "string": "hello"
- }
- ]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement