Skip to content

Commit

Permalink
Benchmark additionalProperties with only type inside (#1211)
Browse files Browse the repository at this point in the history
Signed-off-by: Juan Cruz Viotti <[email protected]>
  • Loading branch information
jviotti authored Sep 23, 2024
1 parent efb9776 commit b5496c2
Showing 1 changed file with 51 additions and 0 deletions.
51 changes: 51 additions & 0 deletions benchmark/jsonschema_validator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -711,6 +711,56 @@ JSONSchema_Validate_Draft4_Ref_To_Single_Property(benchmark::State &state) {
}
}

static void
JSONSchema_Validate_Draft4_Additional_Properties_Type(benchmark::State &state) {
const sourcemeta::jsontoolkit::JSON schema{
sourcemeta::jsontoolkit::parse(R"JSON({
"$schema": "http://json-schema.org/draft-04/schema#",
"additionalProperties": { "type": "boolean" }
})JSON")};

const sourcemeta::jsontoolkit::JSON instance{
sourcemeta::jsontoolkit::parse(R"JSON({
"a": true,
"b": true,
"c": true,
"d": true,
"e": true,
"f": true,
"g": true,
"h": true,
"i": true,
"j": true,
"k": true,
"l": true,
"m": true,
"n": true,
"o": true,
"p": true,
"q": true,
"r": true,
"s": true,
"t": true,
"u": true,
"v": true,
"w": true,
"x": true,
"y": true,
"z": true
})JSON")};

const auto schema_template{sourcemeta::jsontoolkit::compile(
schema, sourcemeta::jsontoolkit::default_schema_walker,
sourcemeta::jsontoolkit::official_resolver,
sourcemeta::jsontoolkit::default_schema_compiler)};

for (auto _ : state) {
auto result{sourcemeta::jsontoolkit::evaluate(schema_template, instance)};
assert(result);
benchmark::DoNotOptimize(result);
}
}

BENCHMARK(JSONSchema_Validate_Draft4_Meta_1_No_Callback);
BENCHMARK(JSONSchema_Validate_Draft4_Required_Properties);
BENCHMARK(JSONSchema_Validate_Draft4_Many_Optional_Properties_Minimal_Match);
Expand All @@ -723,3 +773,4 @@ BENCHMARK(JSONSchema_Validate_Draft4_Properties_Triad_Required);
BENCHMARK(JSONSchema_Validate_Draft4_Non_Recursive_Ref);
BENCHMARK(JSONSchema_Validate_Draft4_Pattern_Properties_True);
BENCHMARK(JSONSchema_Validate_Draft4_Ref_To_Single_Property);
BENCHMARK(JSONSchema_Validate_Draft4_Additional_Properties_Type);

4 comments on commit b5496c2

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Benchmark (macos/llvm)

Benchmark suite Current: b5496c2 Previous: efb9776 Ratio
JSONSchema_Validate_Draft4_Meta_1_No_Callback 718.8056340438887 ns/iter 801.3294090718083 ns/iter 0.90
JSONSchema_Validate_Draft4_Required_Properties 809.2799501108497 ns/iter 863.6115663423917 ns/iter 0.94
JSONSchema_Validate_Draft4_Many_Optional_Properties_Minimal_Match 141.976728222745 ns/iter 155.30629017356915 ns/iter 0.91
JSONSchema_Validate_Draft4_Few_Optional_Properties_Minimal_Match 106.31137759327929 ns/iter 115.97240864695749 ns/iter 0.92
JSONSchema_Validate_Draft4_Items_Schema 2089.948540273126 ns/iter 2246.945087132407 ns/iter 0.93
JSONSchema_Validate_Draft4_Nested_Object 1296.5783962868566 ns/iter 1455.3519536782733 ns/iter 0.89
JSONSchema_Validate_Draft4_Properties_Triad_Optional 1403.2854238783864 ns/iter 1616.773009974131 ns/iter 0.87
JSONSchema_Validate_Draft4_Properties_Triad_Closed 1016.4759371470143 ns/iter 1088.4847027637916 ns/iter 0.93
JSONSchema_Validate_Draft4_Properties_Triad_Required 1351.2359847507064 ns/iter 1460.591311966448 ns/iter 0.93
JSONSchema_Validate_Draft4_Non_Recursive_Ref 485.0102890414495 ns/iter 540.398775060151 ns/iter 0.90
JSONSchema_Validate_Draft4_Pattern_Properties_True 1335.8462609048331 ns/iter 1871.1575913750603 ns/iter 0.71
JSONSchema_Validate_Draft4_Ref_To_Single_Property 109.85730314088799 ns/iter 161.91300277319075 ns/iter 0.68
JSONSchema_Validate_Draft4_Additional_Properties_Type 607.8258311618016 ns/iter

This comment was automatically generated by workflow using github-action-benchmark.

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Benchmark (linux/llvm)

Benchmark suite Current: b5496c2 Previous: efb9776 Ratio
JSONSchema_Validate_Draft4_Meta_1_No_Callback 16863.505879494653 ns/iter 17226.7991384629 ns/iter 0.98
JSONSchema_Validate_Draft4_Required_Properties 7199.058394685412 ns/iter 6930.780995242423 ns/iter 1.04
JSONSchema_Validate_Draft4_Many_Optional_Properties_Minimal_Match 1852.8524072799921 ns/iter 1898.85531812982 ns/iter 0.98
JSONSchema_Validate_Draft4_Few_Optional_Properties_Minimal_Match 891.923311106897 ns/iter 896.6698709328912 ns/iter 0.99
JSONSchema_Validate_Draft4_Items_Schema 115605.86972176732 ns/iter 119697.23220339169 ns/iter 0.97
JSONSchema_Validate_Draft4_Nested_Object 54210.99690330504 ns/iter 55761.39679645209 ns/iter 0.97
JSONSchema_Validate_Draft4_Properties_Triad_Optional 8922.170623599046 ns/iter 8855.576460826605 ns/iter 1.01
JSONSchema_Validate_Draft4_Properties_Triad_Closed 8399.559822729583 ns/iter 8294.245323154393 ns/iter 1.01
JSONSchema_Validate_Draft4_Properties_Triad_Required 9076.201339938718 ns/iter 8993.832075520568 ns/iter 1.01
JSONSchema_Validate_Draft4_Non_Recursive_Ref 4320.309868513465 ns/iter 4218.882254376694 ns/iter 1.02
JSONSchema_Validate_Draft4_Pattern_Properties_True 6347.999564858741 ns/iter 6185.4943527212645 ns/iter 1.03
JSONSchema_Validate_Draft4_Ref_To_Single_Property 896.0627892339013 ns/iter 896.2427334868452 ns/iter 1.00
JSONSchema_Validate_Draft4_Additional_Properties_Type 7179.903897025245 ns/iter

This comment was automatically generated by workflow using github-action-benchmark.

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Benchmark (linux/gcc)

Benchmark suite Current: b5496c2 Previous: efb9776 Ratio
JSONSchema_Validate_Draft4_Meta_1_No_Callback 1070.430545460168 ns/iter 1124.7516135193764 ns/iter 0.95
JSONSchema_Validate_Draft4_Required_Properties 2206.7956584088975 ns/iter 2219.181088489953 ns/iter 0.99
JSONSchema_Validate_Draft4_Many_Optional_Properties_Minimal_Match 189.37367667295823 ns/iter 188.72426216577188 ns/iter 1.00
JSONSchema_Validate_Draft4_Few_Optional_Properties_Minimal_Match 159.83687713030267 ns/iter 154.74086221760112 ns/iter 1.03
JSONSchema_Validate_Draft4_Items_Schema 3603.457103393002 ns/iter 3663.5800950389107 ns/iter 0.98
JSONSchema_Validate_Draft4_Nested_Object 1723.82923747386 ns/iter 1744.8957984735894 ns/iter 0.99
JSONSchema_Validate_Draft4_Properties_Triad_Optional 1805.3331304241638 ns/iter 1809.1025454022401 ns/iter 1.00
JSONSchema_Validate_Draft4_Properties_Triad_Closed 1421.5981518667563 ns/iter 1467.2019172380367 ns/iter 0.97
JSONSchema_Validate_Draft4_Properties_Triad_Required 1827.9558071480972 ns/iter 1866.671226875222 ns/iter 0.98
JSONSchema_Validate_Draft4_Non_Recursive_Ref 757.6728419966686 ns/iter 752.810658665689 ns/iter 1.01
JSONSchema_Validate_Draft4_Pattern_Properties_True 2447.887134594708 ns/iter 2409.2308515524965 ns/iter 1.02
JSONSchema_Validate_Draft4_Ref_To_Single_Property 171.1859210072774 ns/iter 164.37836009369818 ns/iter 1.04
JSONSchema_Validate_Draft4_Additional_Properties_Type 1469.6460983569393 ns/iter

This comment was automatically generated by workflow using github-action-benchmark.

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Benchmark (windows/msvc)

Benchmark suite Current: b5496c2 Previous: efb9776 Ratio
JSONSchema_Validate_Draft4_Meta_1_No_Callback 2984.9017553824383 ns/iter 2963.785842426494 ns/iter 1.01
JSONSchema_Validate_Draft4_Required_Properties 1623.6733100403148 ns/iter 1603.7721626525783 ns/iter 1.01
JSONSchema_Validate_Draft4_Many_Optional_Properties_Minimal_Match 607.8116071429512 ns/iter 590.7068750001291 ns/iter 1.03
JSONSchema_Validate_Draft4_Few_Optional_Properties_Minimal_Match 433.11099999996827 ns/iter 425.29803966706794 ns/iter 1.02
JSONSchema_Validate_Draft4_Items_Schema 11495.201562500059 ns/iter 11453.767187500574 ns/iter 1.00
JSONSchema_Validate_Draft4_Nested_Object 6723.01785714272 ns/iter 6765.745535714375 ns/iter 0.99
JSONSchema_Validate_Draft4_Properties_Triad_Optional 5811.19642857126 ns/iter 5863.274107144077 ns/iter 0.99
JSONSchema_Validate_Draft4_Properties_Triad_Closed 4818.276603296468 ns/iter 4670.101564574265 ns/iter 1.03
JSONSchema_Validate_Draft4_Properties_Triad_Required 5843.740000000253 ns/iter 5681.637499999884 ns/iter 1.03
JSONSchema_Validate_Draft4_Non_Recursive_Ref 1183.1432142855647 ns/iter 1192.625312500084 ns/iter 0.99
JSONSchema_Validate_Draft4_Pattern_Properties_True 8223.366413540778 ns/iter 8002.720982143481 ns/iter 1.03
JSONSchema_Validate_Draft4_Ref_To_Single_Property 438.5238750001008 ns/iter 439.033625000036 ns/iter 1.00
JSONSchema_Validate_Draft4_Additional_Properties_Type 1599.6614064766843 ns/iter

This comment was automatically generated by workflow using github-action-benchmark.

Please sign in to comment.