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);
|
|
|
|
|
2020-03-29 05:48:43 +08:00
|
|
|
SIMDJSON_PUSH_DISABLE_WARNINGS
|
|
|
|
SIMDJSON_DISABLE_DEPRECATED_WARNING
|
2020-02-15 07:20:17 +08:00
|
|
|
static void json_parse(State& state) {
|
2020-03-31 02:54:01 +08:00
|
|
|
ParsedJson pj;
|
|
|
|
if (!pj.allocate_capacity(EMPTY_ARRAY.length())) { return; }
|
2020-02-15 07:20:17 +08:00
|
|
|
for (auto _ : state) {
|
2020-03-31 02:54:01 +08:00
|
|
|
auto error = json_parse(EMPTY_ARRAY, pj);
|
2020-02-15 07:20:17 +08:00
|
|
|
if (error) { return; }
|
|
|
|
}
|
|
|
|
}
|
2020-03-29 05:48:43 +08:00
|
|
|
SIMDJSON_POP_DISABLE_WARNINGS
|
2020-02-15 07:20:17 +08:00
|
|
|
BENCHMARK(json_parse);
|
|
|
|
static void parser_parse_error_code(State& state) {
|
2020-03-29 02:43:41 +08:00
|
|
|
dom::parser parser;
|
2020-03-31 02:54:01 +08:00
|
|
|
if (parser.allocate(EMPTY_ARRAY.length())) { return; }
|
2020-02-15 07:20:17 +08:00
|
|
|
for (auto _ : state) {
|
2020-04-15 08:26:26 +08:00
|
|
|
auto error = parser.parse(EMPTY_ARRAY).error();
|
2020-02-15 07:20:17 +08:00
|
|
|
if (error) { return; }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
BENCHMARK(parser_parse_error_code);
|
|
|
|
static void parser_parse_exception(State& state) {
|
2020-03-29 02:43:41 +08:00
|
|
|
dom::parser parser;
|
2020-03-31 02:54:01 +08:00
|
|
|
if (parser.allocate(EMPTY_ARRAY.length())) { return; }
|
2020-02-15 07:20:17 +08:00
|
|
|
for (auto _ : state) {
|
|
|
|
try {
|
2020-03-29 02:43:41 +08:00
|
|
|
UNUSED dom::element 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);
|
|
|
|
|
2020-03-29 05:48:43 +08:00
|
|
|
SIMDJSON_PUSH_DISABLE_WARNINGS
|
|
|
|
SIMDJSON_DISABLE_DEPRECATED_WARNING
|
2020-02-15 07:20:17 +08:00
|
|
|
static void build_parsed_json(State& state) {
|
|
|
|
for (auto _ : state) {
|
2020-03-29 02:43:41 +08:00
|
|
|
dom::parser parser = simdjson::build_parsed_json(EMPTY_ARRAY);
|
2020-02-15 07:20:17 +08:00
|
|
|
if (!parser.valid) { return; }
|
|
|
|
}
|
|
|
|
}
|
2020-03-29 05:48:43 +08:00
|
|
|
SIMDJSON_POP_DISABLE_WARNINGS
|
2020-02-15 07:20:17 +08:00
|
|
|
BENCHMARK(build_parsed_json);
|
|
|
|
static void document_parse_error_code(State& state) {
|
|
|
|
for (auto _ : state) {
|
2020-03-29 02:43:41 +08:00
|
|
|
dom::parser parser;
|
2020-04-15 08:26:26 +08:00
|
|
|
auto error = parser.parse(EMPTY_ARRAY).error();
|
2020-02-15 07:20:17 +08:00
|
|
|
if (error) { return; }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
BENCHMARK(document_parse_error_code);
|
|
|
|
static void document_parse_exception(State& state) {
|
|
|
|
for (auto _ : state) {
|
|
|
|
try {
|
2020-03-29 02:43:41 +08:00
|
|
|
dom::parser parser;
|
|
|
|
UNUSED dom::element 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(document_parse_exception);
|
|
|
|
|
|
|
|
BENCHMARK_MAIN();
|