perf: Simplify object comparison
This commit is contained in:
parent
2b807f2364
commit
089c623b29
|
@ -80,7 +80,7 @@ fn main() -> Result<(), CompilationError> {
|
|||
|
||||
## Performance
|
||||
|
||||
There is a comparison with other JSON Schema validators written in Rust - `jsonschema_valid==0.4.0` and `valico==3.5.0`.
|
||||
There is a comparison with other JSON Schema validators written in Rust - `jsonschema_valid==0.4.0` and `valico==3.6.0`.
|
||||
|
||||
Test machine i8700K (12 cores), 32GB RAM.
|
||||
|
||||
|
@ -94,9 +94,9 @@ Ratios are given against compiled `JSONSchema` using its `validate`. The `is_val
|
|||
|
||||
| Case | jsonschema_valid | valico | jsonschema.validate | jsonschema.is_valid |
|
||||
| ------------- | ----------------------- | ----------------------- | --------------------- | ---------------------- |
|
||||
| Big valid | - | 95.008 ms (**x17.35**) | 5.473 ms | 3.778 ms (**x0.69**) |
|
||||
| Small valid | 2.04 us (**x5.62**) | 3.67 us (**x10.11**) | 362.87 ns | 100.52 ns (**x0.27**) |
|
||||
| Small invalid | 397.52 ns (**x0.80**) | 3.73 us (**x7.55**) | 493.85 ns | 5.80 ns (**x0.01**) |
|
||||
| Big valid | - | 90.654 ms (**x16.57**) | 5.468 ms | 3.688 ms (**x0.67**) |
|
||||
| Small valid | 2.04 us (**x5.67**) | 3.70 us (**x10.28**) | 359.59 ns | 93.40 ns (**x0.25**) |
|
||||
| Small invalid | 397.52 ns (**x0.81**) | 3.78 us (**x7.75**) | 487.25 ns | 5.15 ns (**x0.01**) |
|
||||
|
||||
Unfortunately, `jsonschema_valid` mistakenly considers the Kubernetes Open API schema as invalid and therefore can't be compared with other libraries in this case.
|
||||
|
||||
|
|
|
@ -39,8 +39,8 @@ fraction = { version = "0.8", default-features = false, features = ["with-bigint
|
|||
criterion = ">= 0.1"
|
||||
mockito = ">= 0"
|
||||
json_schema_test_suite = ">= 0.3"
|
||||
jsonschema-valid = ">= 0.1"
|
||||
valico = "3"
|
||||
jsonschema-valid = "0.4.0"
|
||||
valico = "3.6.0"
|
||||
test-case = "1"
|
||||
paste = ">= 0.1"
|
||||
reqwest = { version = ">= 0.10", features = ["blocking", "json"] }
|
||||
|
|
|
@ -16,6 +16,9 @@ macro_rules! num_cmp {
|
|||
#[inline]
|
||||
pub(crate) fn equal(left: &Value, right: &Value) -> bool {
|
||||
match (left, right) {
|
||||
(Value::String(left), Value::String(right)) => left == right,
|
||||
(Value::Bool(left), Value::Bool(right)) => left == right,
|
||||
(Value::Null, Value::Null) => true,
|
||||
(Value::Number(left), Value::Number(right)) => {
|
||||
if let Some(a) = left.as_u64() {
|
||||
num_cmp!(a, right)
|
||||
|
@ -28,7 +31,7 @@ pub(crate) fn equal(left: &Value, right: &Value) -> bool {
|
|||
}
|
||||
(Value::Array(left), Value::Array(right)) => equal_arrays(left, right),
|
||||
(Value::Object(left), Value::Object(right)) => equal_objects(left, right),
|
||||
(_, _) => left == right,
|
||||
(_, _) => false,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
//! Facilities for working with paths within schemas or validated instances.
|
||||
use std::fmt;
|
||||
use std::fmt::Write;
|
||||
use std::{fmt, fmt::Write};
|
||||
|
||||
#[derive(Clone, Debug, Eq, PartialEq)]
|
||||
/// JSON Pointer as a wrapper around individual path components
|
||||
|
|
Loading…
Reference in New Issue