|
7 | 7 |
|
8 | 8 | #include <sourcemeta/blaze/compiler.h> |
9 | 9 | #include <sourcemeta/blaze/evaluator.h> |
| 10 | +#include <sourcemeta/blaze/output.h> |
10 | 11 |
|
11 | 12 | static void Micro_2020_12_Dynamic_Ref(benchmark::State &state) { |
12 | 13 | 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) { |
96 | 97 | } |
97 | 98 | } |
98 | 99 |
|
| 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 | + |
99 | 216 | BENCHMARK(Micro_2020_12_Dynamic_Ref); |
100 | 217 | 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