From d5dc324248ddd9c9c118eea40961d36d2a42e938 Mon Sep 17 00:00:00 2001 From: Juan Cruz Viotti Date: Wed, 16 Oct 2024 16:01:14 -0400 Subject: [PATCH] Add a simple `unevaluatedProperties` benchmark case Signed-off-by: Juan Cruz Viotti --- benchmark/CMakeLists.txt | 1 + benchmark/evaluator_2019_09.cc | 45 ++++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+) create mode 100644 benchmark/evaluator_2019_09.cc diff --git a/benchmark/CMakeLists.txt b/benchmark/CMakeLists.txt index c9bb0cc6..b04ff0ff 100644 --- a/benchmark/CMakeLists.txt +++ b/benchmark/CMakeLists.txt @@ -8,6 +8,7 @@ if(BLAZE_EVALUATOR) evaluator_draft4.cc evaluator_draft6.cc evaluator_draft7.cc + evaluator_2019_09.cc evaluator_2020_12.cc) endif() diff --git a/benchmark/evaluator_2019_09.cc b/benchmark/evaluator_2019_09.cc new file mode 100644 index 00000000..26aeabcb --- /dev/null +++ b/benchmark/evaluator_2019_09.cc @@ -0,0 +1,45 @@ +#include + +#include // assert + +#include +#include + +#include +#include + +static void Evaluator_2019_09_Unevaluated_Properties(benchmark::State &state) { + const sourcemeta::jsontoolkit::JSON schema{ + sourcemeta::jsontoolkit::parse(R"JSON({ + "$schema": "https://json-schema.org/draft/2019-09/schema", + "type": "object", + "properties": { + "name": true, + "prohibited": false + }, + "unevaluatedProperties": false, + "$ref": "#/$defs/extension", + "$defs": { + "extension": { + "patternProperties": { "^x-": true } + } + } + })JSON")}; + + const auto instance{sourcemeta::jsontoolkit::parse(R"JSON({ + "name": "John Doe", + "x-foo": "bar" + })JSON")}; + + const auto schema_template{sourcemeta::blaze::compile( + schema, sourcemeta::jsontoolkit::default_schema_walker, + sourcemeta::jsontoolkit::official_resolver, + sourcemeta::blaze::default_schema_compiler)}; + for (auto _ : state) { + auto result{sourcemeta::blaze::evaluate(schema_template, instance)}; + assert(result); + benchmark::DoNotOptimize(result); + } +} + +BENCHMARK(Evaluator_2019_09_Unevaluated_Properties);