-
-
Notifications
You must be signed in to change notification settings - Fork 97
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
perf: Optimize error formatting in some cases
Signed-off-by: Dmitry Dygalo <[email protected]>
- Loading branch information
1 parent
37c64d4
commit 88e4a01
Showing
7 changed files
with
217 additions
and
89 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
[ | ||
{ | ||
"name": "additional_properties", | ||
"schema": { | ||
"type": "object", | ||
"properties": { | ||
"foo": { | ||
"type": "string" | ||
} | ||
}, | ||
"additionalProperties": false | ||
}, | ||
"instance": { | ||
"foo": "bar", | ||
"extra1": "value1", | ||
"extra2": "value2", | ||
"extra3": "value3" | ||
} | ||
}, | ||
{ | ||
"name": "type_multiple", | ||
"schema": { | ||
"type": [ | ||
"string", | ||
"number", | ||
"boolean", | ||
"null", | ||
"array" | ||
] | ||
}, | ||
"instance": { | ||
"type": "object" | ||
} | ||
}, | ||
{ | ||
"name": "unevaluated_properties", | ||
"schema": { | ||
"type": "object", | ||
"properties": { | ||
"foo": { | ||
"type": "string" | ||
} | ||
}, | ||
"unevaluatedProperties": false | ||
}, | ||
"instance": { | ||
"foo": "bar", | ||
"extra1": "value1", | ||
"extra2": "value2" | ||
} | ||
}, | ||
{ | ||
"name": "unevaluated_items", | ||
"schema": { | ||
"type": "array", | ||
"prefixItems": [ | ||
{ | ||
"type": "integer" | ||
} | ||
], | ||
"unevaluatedItems": false | ||
}, | ||
"instance": [ | ||
1, | ||
2, | ||
3, | ||
4, | ||
5 | ||
] | ||
} | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -59,3 +59,8 @@ name = "jsonschema" | |
[[bench]] | ||
harness = false | ||
name = "keywords" | ||
|
||
[[bench]] | ||
harness = false | ||
name = "errors" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
use benchmark::run_error_formatting_benchmarks; | ||
use criterion::{criterion_group, criterion_main, BenchmarkId, Criterion}; | ||
use serde_json::Value; | ||
|
||
fn bench_error_formatting(c: &mut Criterion, name: &str, schema: &Value, instance: &Value) { | ||
let validator = jsonschema::validator_for(schema).expect("Valid schema"); | ||
let error = validator | ||
.validate(instance) | ||
.unwrap_err() | ||
.next() | ||
.expect("Should have at least one error"); | ||
|
||
c.bench_with_input( | ||
BenchmarkId::new("error_formatting", name), | ||
&error, | ||
|b, error| b.iter(|| error.to_string()), | ||
); | ||
} | ||
|
||
fn run_benchmarks(c: &mut Criterion) { | ||
run_error_formatting_benchmarks(&mut |name, schema, instance| { | ||
bench_error_formatting(c, name, schema, instance); | ||
}); | ||
} | ||
|
||
criterion_group!(error_formatting, run_benchmarks); | ||
criterion_main!(error_formatting); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters