-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprogram.cpp
More file actions
52 lines (39 loc) · 1.74 KB
/
program.cpp
File metadata and controls
52 lines (39 loc) · 1.74 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
#include "simdjson.h"
#include <iostream>
#include <filesystem>
int main(int argc, char* argv[], char* envp[]) {
if (argc < 2) {
std::cout << "simdjson v" << STRINGIFY(SIMDJSON_VERSION) << std::endl;
std::cout << "Detected the best implementation for your machine: " << simdjson::active_implementation->name();
std::cout << "(" << simdjson::active_implementation->description() << ")" << std::endl << std::endl;
std::cout << "Available implementations:" << std::endl;
for (auto implementation : simdjson::available_implementations) {
std::cout << implementation->name() << ": " << implementation->description() << std::endl;
}
std::cout << std::endl;
std::cout << "Usage:" << std::endl << argv[0] << " <directory> [simdjson implementation]" << std::endl;
}
else {
std::string path = argv[1];
if (argc >= 3) {
std::string impl = argv[2];
simdjson::active_implementation = simdjson::available_implementations[impl];
}
std::cout << "Reading json files from: " << path << std::endl;
std::cout << "Using simdjson implementation: " << simdjson::active_implementation->name() << std::endl;
auto t1 = std::chrono::high_resolution_clock::now();
simdjson::dom::parser parser;
int fileCount = 0;
for (const auto& entry : std::filesystem::directory_iterator(path)) {
if (entry.path().extension() == ".json") {
std::cout << entry.path() << " - ";
simdjson::dom::element data = parser.load(entry.path().string());
std::cout << data["count"] << std::endl;
fileCount++;
}
}
auto t2 = std::chrono::high_resolution_clock::now();
std::chrono::duration<double, std::milli> fp_ms = t2 - t1;
std::cout << std::endl << "Processed " << fileCount << " file(s) in " << fp_ms.count() << " second(s)" << std::endl;
}
}