Skip to content

Commit 182df37

Browse files
authored
Add micro benchmark cases for SimpleOutput (#547)
Signed-off-by: Juan Cruz Viotti <jv@jviotti.com>
1 parent ea74ae7 commit 182df37

2 files changed

Lines changed: 124 additions & 1 deletion

File tree

benchmark/CMakeLists.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
set(BENCHMARK_SOURCES)
22

3-
if(BLAZE_COMPILER AND BLAZE_EVALUATOR)
3+
if(BLAZE_COMPILER AND BLAZE_EVALUATOR AND BLAZE_OUTPUT)
44
list(APPEND BENCHMARK_SOURCES
55
e2e/runner.cc
66
micro/draft4.cc
@@ -33,6 +33,10 @@ if(BENCHMARK_SOURCES)
3333
target_link_libraries(sourcemeta_blaze_benchmark
3434
PRIVATE sourcemeta::blaze::evaluator)
3535
endif()
36+
if(BLAZE_OUTPUT)
37+
target_link_libraries(sourcemeta_blaze_benchmark
38+
PRIVATE sourcemeta::blaze::output)
39+
endif()
3640

3741
add_custom_target(benchmark_all
3842
COMMAND sourcemeta_blaze_benchmark

benchmark/micro/2020_12.cc

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
#include <sourcemeta/blaze/compiler.h>
99
#include <sourcemeta/blaze/evaluator.h>
10+
#include <sourcemeta/blaze/output.h>
1011

1112
static void Micro_2020_12_Dynamic_Ref(benchmark::State &state) {
1213
const sourcemeta::core::JSON schema{sourcemeta::core::parse_json(R"JSON({
@@ -96,5 +97,123 @@ static void Micro_2020_12_Dynamic_Ref_Single(benchmark::State &state) {
9697
}
9798
}
9899

100+
static void Micro_2020_12_Simple_Output_Mask(benchmark::State &state) {
101+
const sourcemeta::core::JSON schema{sourcemeta::core::parse_json(R"JSON({
102+
"$schema": "https://json-schema.org/draft/2020-12/schema",
103+
"type": "object",
104+
"properties": {
105+
"data": {
106+
"oneOf": [
107+
{
108+
"anyOf": [
109+
{ "type": "string", "minLength": 100 },
110+
{ "type": "number", "minimum": 1000 },
111+
{ "type": "boolean" }
112+
]
113+
},
114+
{
115+
"anyOf": [
116+
{ "type": "string", "pattern": "^[A-Z]+$" },
117+
{ "type": "array", "minItems": 50 },
118+
{ "type": "object", "required": ["x", "y", "z"] }
119+
]
120+
},
121+
{
122+
"anyOf": [
123+
{ "type": "null" },
124+
{ "type": "integer", "multipleOf": 7 },
125+
{ "type": "string", "maxLength": 2 }
126+
]
127+
},
128+
{
129+
"type": "array",
130+
"contains": {
131+
"oneOf": [
132+
{ "type": "string", "minLength": 20 },
133+
{ "type": "number", "minimum": 100 },
134+
{ "const": "special" }
135+
]
136+
},
137+
"minContains": 3
138+
},
139+
{
140+
"type": "array",
141+
"items": {
142+
"anyOf": [
143+
{ "type": "number", "maximum": 50 },
144+
{ "type": "string", "maxLength": 10 }
145+
]
146+
},
147+
"minItems": 1
148+
}
149+
]
150+
}
151+
}
152+
})JSON")};
153+
154+
const auto instance{sourcemeta::core::parse_json(R"JSON({
155+
"data": [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, "a", "b", "c", "d", "e" ]
156+
})JSON")};
157+
158+
const auto schema_template{sourcemeta::blaze::compile(
159+
schema, sourcemeta::core::schema_official_walker,
160+
sourcemeta::core::schema_official_resolver,
161+
sourcemeta::blaze::default_schema_compiler)};
162+
sourcemeta::blaze::Evaluator evaluator;
163+
for (auto _ : state) {
164+
sourcemeta::blaze::SimpleOutput output{instance};
165+
auto result{
166+
evaluator.validate(schema_template, instance, std::ref(output))};
167+
assert(result);
168+
benchmark::DoNotOptimize(result);
169+
}
170+
}
171+
172+
static void Micro_2020_12_Simple_Output_Annotations(benchmark::State &state) {
173+
const sourcemeta::core::JSON schema{sourcemeta::core::parse_json(R"JSON({
174+
"$schema": "https://json-schema.org/draft/2020-12/schema",
175+
"type": "array",
176+
"allOf": [
177+
{ "contains": { "type": "number" } },
178+
{ "contains": { "type": "number" } },
179+
{ "contains": { "type": "number" } },
180+
{ "contains": { "type": "string" } },
181+
{ "contains": { "type": "string" } },
182+
{ "contains": { "type": "string" } },
183+
{ "contains": { "type": "boolean" } },
184+
{ "contains": { "type": "null" } },
185+
{ "contains": { "type": "number" } },
186+
{ "contains": { "type": "number" } }
187+
]
188+
})JSON")};
189+
190+
const auto instance{sourcemeta::core::parse_json(R"JSON([
191+
1, 2, 3, 4, 5, 6, 7, 8, 9, 10,
192+
11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
193+
21, 22, 23, 24, 25, 26, 27, 28, 29, 30,
194+
"a", "b", "c", "aa", "bb", "cc",
195+
"abc", "def", "ghi",
196+
"ABC", "DEF", "GHI",
197+
true, false, true,
198+
null, null,
199+
42, 48, 54, 60
200+
])JSON")};
201+
202+
const auto schema_template{sourcemeta::blaze::compile(
203+
schema, sourcemeta::core::schema_official_walker,
204+
sourcemeta::core::schema_official_resolver,
205+
sourcemeta::blaze::default_schema_compiler)};
206+
sourcemeta::blaze::Evaluator evaluator;
207+
for (auto _ : state) {
208+
sourcemeta::blaze::SimpleOutput output{instance};
209+
auto result{
210+
evaluator.validate(schema_template, instance, std::ref(output))};
211+
assert(result);
212+
benchmark::DoNotOptimize(result);
213+
}
214+
}
215+
99216
BENCHMARK(Micro_2020_12_Dynamic_Ref);
100217
BENCHMARK(Micro_2020_12_Dynamic_Ref_Single);
218+
BENCHMARK(Micro_2020_12_Simple_Output_Mask);
219+
BENCHMARK(Micro_2020_12_Simple_Output_Annotations);

0 commit comments

Comments
 (0)