2020-02-15 07:20:17 +08:00
|
|
|
#include <benchmark/benchmark.h>
|
2020-03-03 06:23:19 +08:00
|
|
|
#include "simdjson.h"
|
2020-02-15 07:20:17 +08:00
|
|
|
using namespace simdjson;
|
|
|
|
using namespace benchmark;
|
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
const padded_string EMPTY_ARRAY("[]", 2);
|
|
|
|
|
|
|
|
static void json_parse(State& state) {
|
|
|
|
document::parser parser;
|
2020-03-07 07:40:59 +08:00
|
|
|
if (parser.set_capacity(EMPTY_ARRAY.length())) { return; }
|
2020-02-15 07:20:17 +08:00
|
|
|
for (auto _ : state) {
|
|
|
|
auto error = simdjson::json_parse(EMPTY_ARRAY, parser);
|
|
|
|
if (error) { return; }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
BENCHMARK(json_parse);
|
|
|
|
static void parser_parse_error_code(State& state) {
|
|
|
|
document::parser parser;
|
2020-03-07 07:40:59 +08:00
|
|
|
if (parser.set_capacity(EMPTY_ARRAY.length())) { return; }
|
2020-02-15 07:20:17 +08:00
|
|
|
for (auto _ : state) {
|
|
|
|
auto [doc, error] = parser.parse(EMPTY_ARRAY);
|
|
|
|
if (error) { return; }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
BENCHMARK(parser_parse_error_code);
|
|
|
|
static void parser_parse_exception(State& state) {
|
|
|
|
document::parser parser;
|
2020-03-07 07:40:59 +08:00
|
|
|
if (parser.set_capacity(EMPTY_ARRAY.length())) { return; }
|
2020-02-15 07:20:17 +08:00
|
|
|
for (auto _ : state) {
|
|
|
|
try {
|
|
|
|
UNUSED document &doc = parser.parse(EMPTY_ARRAY);
|
2020-03-07 04:36:44 +08:00
|
|
|
} catch(simdjson_error &j) {
|
2020-02-15 07:20:17 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
BENCHMARK(parser_parse_exception);
|
|
|
|
|
|
|
|
static void build_parsed_json(State& state) {
|
|
|
|
for (auto _ : state) {
|
|
|
|
document::parser parser = simdjson::build_parsed_json(EMPTY_ARRAY);
|
|
|
|
if (!parser.valid) { return; }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
BENCHMARK(build_parsed_json);
|
|
|
|
static void document_parse_error_code(State& state) {
|
|
|
|
for (auto _ : state) {
|
|
|
|
auto [doc, error] = document::parse(EMPTY_ARRAY);
|
|
|
|
if (error) { return; }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
BENCHMARK(document_parse_error_code);
|
|
|
|
static void document_parse_exception(State& state) {
|
|
|
|
for (auto _ : state) {
|
|
|
|
try {
|
|
|
|
UNUSED document doc = document::parse(EMPTY_ARRAY);
|
2020-03-07 04:36:44 +08:00
|
|
|
} catch(simdjson_error &j) {
|
2020-02-15 07:20:17 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
BENCHMARK(document_parse_exception);
|
|
|
|
|
|
|
|
BENCHMARK_MAIN();
|