forked from nique_372/JsonParserByLeo
127 lines
No EOL
4.6 KiB
C++
127 lines
No EOL
4.6 KiB
C++
#include <iostream>
|
|
#include <chrono>
|
|
#include "simdjson.h"
|
|
|
|
int main()
|
|
{
|
|
// aliases
|
|
using clock = std::chrono::high_resolution_clock;
|
|
using ms = std::chrono::duration<double, std::milli>;
|
|
|
|
// Ruta al archivo
|
|
const char* JSON_PATH = R"(C:\Users\USER\AppData\Roaming\MetaQuotes\Terminal\D0E8209F77C8CF37AD8BF550E51FF075\MQL5\Shared Projects\JsonParserByLeo\Test\Ben\twitter.json)";
|
|
|
|
// Inputs base
|
|
constexpr int WARMUP = 20;
|
|
constexpr int ITERS = 1000;
|
|
|
|
// Cargar archivo
|
|
simdjson::padded_string json;
|
|
auto err = simdjson::padded_string::load(JSON_PATH).get(json);
|
|
if (err) {
|
|
std::cerr << "No se pudo abrir: " << JSON_PATH << "\n"
|
|
<< simdjson::error_message(err) << "\n";
|
|
return 1;
|
|
}
|
|
std::cout << "Archivo: " << json.size() / 1024 << " KB\n";
|
|
|
|
// Parser unico se reutiliza en cada iteracion
|
|
simdjson::dom::parser parser;
|
|
|
|
// Warm-up
|
|
std::cout << "Warm-up (" << WARMUP << " iteraciones)...\n";
|
|
for (int i = 0; i < WARMUP; ++i) {
|
|
parser.parse(json);
|
|
}
|
|
|
|
// Benchmark
|
|
std::cout << "Benchmark (" << ITERS << " iteraciones)...\n";
|
|
|
|
auto t0 = clock::now();
|
|
|
|
for (int i = 0; i < ITERS; ++i) {
|
|
parser.parse(json);
|
|
}
|
|
|
|
auto t1 = clock::now();
|
|
|
|
// Estadísticas
|
|
double total_ms = ms(t1 - t0).count();
|
|
double mean_ms = total_ms / ITERS;
|
|
double file_mb = json.size() / (1024.0 * 1024.0);
|
|
double mean_mb_s = file_mb / (mean_ms / 1000.0);
|
|
|
|
std::cout << "\n────────────────────────────────────\n";
|
|
std::cout << " Archivo : " << json.size() / 1024 << " KB\n";
|
|
std::cout << " Iteraciones : " << ITERS << "\n";
|
|
std::cout << " Total : " << total_ms << " ms\n";
|
|
std::cout << " Media/iter : " << mean_ms << " ms\n";
|
|
std::cout << " Throughput : " << mean_mb_s << " MB/s\n";
|
|
std::cout << "────────────────────────────────────\n";
|
|
|
|
std::this_thread::sleep_for(std::chrono::seconds(10));
|
|
|
|
return 0;
|
|
}
|
|
|
|
/*
|
|
Archivo: 616 KB
|
|
Warm-up (20 iteraciones)...
|
|
Benchmark (1000 iteraciones)...
|
|
|
|
ÔöÇÔöÇÔöÇÔöÇÔöÇÔöÇÔöÇÔöÇÔöÇÔöÇÔöÇÔöÇÔöÇÔöÇÔöÇÔöÇÔöÇÔöÇÔöÇÔöÇÔöÇÔöÇÔöÇÔöÇÔöÇÔöÇÔöÇÔöÇÔöÇÔöÇÔöÇÔöÇÔöÇÔöÇÔöÇÔöÇ
|
|
Archivo : 616 KB
|
|
Iteraciones : 1000
|
|
Total : 382.445 ms
|
|
Media/iter : 0.382445 ms
|
|
Throughput : 1574.76 MB/s
|
|
ÔöÇÔöÇÔöÇÔöÇÔöÇÔöÇÔöÇÔöÇÔöÇÔöÇÔöÇÔöÇÔöÇÔöÇÔöÇÔöÇÔöÇÔöÇÔöÇÔöÇÔöÇÔöÇÔöÇÔöÇÔöÇÔöÇÔöÇÔöÇÔöÇÔöÇÔöÇÔöÇÔöÇÔöÇÔöÇÔöÇ
|
|
|
|
|
|
|
|
|
|
Archivo: 616 KB
|
|
Warm-up (20 iteraciones)...
|
|
Benchmark (1000 iteraciones)...
|
|
|
|
ÔöÇÔöÇÔöÇÔöÇÔöÇÔöÇÔöÇÔöÇÔöÇÔöÇÔöÇÔöÇÔöÇÔöÇÔöÇÔöÇÔöÇÔöÇÔöÇÔöÇÔöÇÔöÇÔöÇÔöÇÔöÇÔöÇÔöÇÔöÇÔöÇÔöÇÔöÇÔöÇÔöÇÔöÇÔöÇÔöÇ
|
|
Archivo : 616 KB
|
|
Iteraciones : 1000
|
|
Total : 385.693 ms
|
|
Media/iter : 0.385693 ms
|
|
Throughput : 1561.5 MB/s
|
|
ÔöÇÔöÇÔöÇÔöÇÔöÇÔöÇÔöÇÔöÇÔöÇÔöÇÔöÇÔöÇÔöÇÔöÇÔöÇÔöÇÔöÇÔöÇÔöÇÔöÇÔöÇÔöÇÔöÇÔöÇÔöÇÔöÇÔöÇÔöÇÔöÇÔöÇÔöÇÔöÇÔöÇÔöÇÔöÇÔöÇ
|
|
|
|
|
|
|
|
|
|
Archivo: 616 KB
|
|
Warm-up (20 iteraciones)...
|
|
Benchmark (1000 iteraciones)...
|
|
|
|
ÔöÇÔöÇÔöÇÔöÇÔöÇÔöÇÔöÇÔöÇÔöÇÔöÇÔöÇÔöÇÔöÇÔöÇÔöÇÔöÇÔöÇÔöÇÔöÇÔöÇÔöÇÔöÇÔöÇÔöÇÔöÇÔöÇÔöÇÔöÇÔöÇÔöÇÔöÇÔöÇÔöÇÔöÇÔöÇÔöÇ
|
|
Archivo : 616 KB
|
|
Iteraciones : 1000
|
|
Total : 380.659 ms
|
|
Media/iter : 0.380659 ms
|
|
Throughput : 1582.15 MB/s
|
|
ÔöÇÔöÇÔöÇÔöÇÔöÇÔöÇÔöÇÔöÇÔöÇÔöÇÔöÇÔöÇÔöÇÔöÇÔöÇÔöÇÔöÇÔöÇÔöÇÔöÇÔöÇÔöÇÔöÇÔöÇÔöÇÔöÇÔöÇÔöÇÔöÇÔöÇÔöÇÔöÇÔöÇÔöÇÔöÇÔöÇ
|
|
|
|
|
|
Archivo: 616 KB
|
|
Warm-up (20 iteraciones)...
|
|
Benchmark (1000 iteraciones)...
|
|
|
|
ÔöÇÔöÇÔöÇÔöÇÔöÇÔöÇÔöÇÔöÇÔöÇÔöÇÔöÇÔöÇÔöÇÔöÇÔöÇÔöÇÔöÇÔöÇÔöÇÔöÇÔöÇÔöÇÔöÇÔöÇÔöÇÔöÇÔöÇÔöÇÔöÇÔöÇÔöÇÔöÇÔöÇÔöÇÔöÇÔöÇ
|
|
Archivo : 616 KB
|
|
Iteraciones : 1000
|
|
Total : 382.245 ms
|
|
Media/iter : 0.382245 ms
|
|
Throughput : 1575.59 MB/s
|
|
ÔöÇÔöÇÔöÇÔöÇÔöÇÔöÇÔöÇÔöÇÔöÇÔöÇÔöÇÔöÇÔöÇÔöÇÔöÇÔöÇÔöÇÔöÇÔöÇÔöÇÔöÇÔöÇÔöÇÔöÇÔöÇÔöÇÔöÇÔöÇÔöÇÔöÇÔöÇÔöÇÔöÇÔöÇÔöÇÔöÇ
|
|
|
|
|
|
|
|
|
|
|
|
*/ |