diff --git a/benches/mod.rs b/benches/mod.rs index 0a0cbf0..2970508 100644 --- a/benches/mod.rs +++ b/benches/mod.rs @@ -10,6 +10,7 @@ use std::str; fn read_10kb_event_stacktrace_offsets_simd(b: &mut test::Bencher) { let input = include_bytes!("../cases/10kb_event_stacktrace.json"); + b.bytes = input.len() as u64; b.iter(|| Document::scan_trusted(input)) } @@ -18,6 +19,7 @@ fn read_10kb_event_stacktrace_offsets_simd_from_const_parts(b: &mut test::Benche let input = include_bytes!("../cases/10kb_event_stacktrace.json"); let const_offsets = Document::scan_trusted(input).into_offsets(); + b.bytes = input.len() as u64; b.iter(|| unsafe { const_offsets.to_document_unchecked(input) }) } @@ -26,6 +28,7 @@ fn read_10kb_event_stacktrace_offsets_simd_reuse(b: &mut test::Bencher) { let input = include_bytes!("../cases/10kb_event_stacktrace.json"); let mut detached = Some(Document::scan_trusted(input).detach()); + b.bytes = input.len() as u64; b.iter(|| { let reuse = detached.take().unwrap(); @@ -40,6 +43,7 @@ fn read_10kb_event_stacktrace_offsets_simd_reuse(b: &mut test::Bencher) { fn read_10kb_event_stacktrace_offsets_fallback(b: &mut test::Bencher) { let input = include_bytes!("../cases/10kb_event_stacktrace.json"); + b.bytes = input.len() as u64; b.iter(|| Document::scan_trusted_fallback(input)) } @@ -47,6 +51,7 @@ fn read_10kb_event_stacktrace_offsets_fallback(b: &mut test::Bencher) { fn read_10kb_event_stacktrace_value_serde_json(b: &mut test::Bencher) { let input = include_bytes!("../cases/10kb_event_stacktrace.json"); + b.bytes = input.len() as u64; b.iter(|| { let v: serde_json::Value = serde_json::from_slice(input).unwrap(); v @@ -57,6 +62,7 @@ fn read_10kb_event_stacktrace_value_serde_json(b: &mut test::Bencher) { fn read_10kb_event_stacktrace_value_json(b: &mut test::Bencher) { let input = include_bytes!("../cases/10kb_event_stacktrace.json"); + b.bytes = input.len() as u64; b.iter(|| { let v: json::JsonValue = json::parse(str::from_utf8(input).unwrap()).unwrap(); v @@ -67,6 +73,7 @@ fn read_10kb_event_stacktrace_value_json(b: &mut test::Bencher) { fn read_10kb_event_stacktrace_value_simd_json(b: &mut test::Bencher) { let input = include_bytes!("../cases/10kb_event_stacktrace.json"); + b.bytes = input.len() as u64; b.iter(|| { let mut input = input.to_vec(); let v = simd_json::to_borrowed_value(&mut input).unwrap(); @@ -78,6 +85,7 @@ fn read_10kb_event_stacktrace_value_simd_json(b: &mut test::Bencher) { fn read_10kb_event_stacktrace_value_to_vec(b: &mut test::Bencher) { let input = include_bytes!("../cases/10kb_event_stacktrace.json"); + b.bytes = input.len() as u64; b.iter(|| input.to_vec()) } @@ -85,6 +93,7 @@ fn read_10kb_event_stacktrace_value_to_vec(b: &mut test::Bencher) { fn read_10kb_event_stacktrace_split(b: &mut test::Bencher) { let input = include_str!("../cases/10kb_event_stacktrace.json"); + b.bytes = input.len() as u64; b.iter(|| input.split('"').for_each(drop)) } @@ -92,6 +101,7 @@ fn read_10kb_event_stacktrace_split(b: &mut test::Bencher) { fn read_10kb_event_stacktrace_validate_utf8(b: &mut test::Bencher) { let input = include_bytes!("../cases/10kb_event_stacktrace.json"); + b.bytes = input.len() as u64; b.iter(|| str::from_utf8(input).unwrap()) } @@ -100,6 +110,7 @@ fn read_10kb_event_stacktrace_validate_utf8(b: &mut test::Bencher) { fn read_10kb_event_stacktrace_offsets_simd_to_serde_json(b: &mut test::Bencher) { let input = include_bytes!("../cases/10kb_event_stacktrace.json"); + b.bytes = input.len() as u64; b.iter(|| Document::scan_trusted(input).to_value()) } @@ -110,6 +121,7 @@ fn convert_10kb_event_stacktrace_offsets_to_serde_json(b: &mut test::Bencher) { let doc = Document::scan_trusted(input); + b.bytes = input.len() as u64; b.iter(|| doc.to_value()) } @@ -117,6 +129,7 @@ fn convert_10kb_event_stacktrace_offsets_to_serde_json(b: &mut test::Bencher) { fn read_10kb_event_stacktrace_offsets_simd_sparse(b: &mut test::Bencher) { let input = include_bytes!("../cases/10kb_event_stacktrace.json"); + b.bytes = input.len() as u64; b.iter(|| { let doc = Document::scan_trusted(input); @@ -137,6 +150,7 @@ fn read_10kb_event_stacktrace_offsets_simd_sparse(b: &mut test::Bencher) { fn read_10kb_event_stacktrace_serde_json_sparse(b: &mut test::Bencher) { let input = include_bytes!("../cases/10kb_event_stacktrace.json"); + b.bytes = input.len() as u64; b.iter(|| { let v: serde_json::Value = serde_json::from_slice(input).unwrap(); @@ -169,6 +183,7 @@ fn unescape_10kb_event_stacktrace(b: &mut test::Bencher) { .as_str() .unwrap(); + b.bytes = input.len() as u64; b.iter(|| stacktrace.to_unescaped()) } @@ -187,6 +202,7 @@ fn unescape_10kb_event_stacktrace_to_string(b: &mut test::Bencher) { .as_str() .unwrap(); + b.bytes = input.len() as u64; b.iter(|| stacktrace.as_raw().to_owned()) } @@ -195,6 +211,7 @@ fn iter_top_level_entries_600b_event_no_escape(b: &mut test::Bencher) { let input = include_bytes!("../cases/600b_event_no_escape.json"); let document = Document::scan_trusted(input); + b.bytes = input.len() as u64; b.iter(|| document.as_map().entries().for_each(drop)) } @@ -202,6 +219,7 @@ fn iter_top_level_entries_600b_event_no_escape(b: &mut test::Bencher) { fn read_600b_event_no_escape_offsets_simd(b: &mut test::Bencher) { let input = include_bytes!("../cases/600b_event_no_escape.json"); + b.bytes = input.len() as u64; b.iter(|| Document::scan_trusted(input)) } @@ -209,6 +227,7 @@ fn read_600b_event_no_escape_offsets_simd(b: &mut test::Bencher) { fn read_600b_event_no_escape_offsets_fallback(b: &mut test::Bencher) { let input = include_bytes!("../cases/600b_event_no_escape.json"); + b.bytes = input.len() as u64; b.iter(|| Document::scan_trusted_fallback(input)) } @@ -216,6 +235,7 @@ fn read_600b_event_no_escape_offsets_fallback(b: &mut test::Bencher) { fn read_600b_event_no_escape_value_serde_json(b: &mut test::Bencher) { let input = include_bytes!("../cases/600b_event_no_escape.json"); + b.bytes = input.len() as u64; b.iter(|| { let v: serde_json::Value = serde_json::from_slice(input).unwrap(); v @@ -226,6 +246,7 @@ fn read_600b_event_no_escape_value_serde_json(b: &mut test::Bencher) { fn read_600b_event_no_escape_value_json(b: &mut test::Bencher) { let input = include_bytes!("../cases/600b_event_no_escape.json"); + b.bytes = input.len() as u64; b.iter(|| { let v: json::JsonValue = json::parse(str::from_utf8(input).unwrap()).unwrap(); v @@ -236,6 +257,7 @@ fn read_600b_event_no_escape_value_json(b: &mut test::Bencher) { fn read_600b_event_no_escape_value_simd_json(b: &mut test::Bencher) { let input = include_bytes!("../cases/600b_event_no_escape.json"); + b.bytes = input.len() as u64; b.iter(|| { let mut input = input.to_vec(); let v = simd_json::to_borrowed_value(&mut input).unwrap(); @@ -247,6 +269,7 @@ fn read_600b_event_no_escape_value_simd_json(b: &mut test::Bencher) { fn read_600b_event_no_escape_value_to_vec(b: &mut test::Bencher) { let input = include_bytes!("../cases/600b_event_no_escape.json"); + b.bytes = input.len() as u64; b.iter(|| input.to_vec()) } @@ -254,6 +277,7 @@ fn read_600b_event_no_escape_value_to_vec(b: &mut test::Bencher) { fn read_600b_event_no_escape_split(b: &mut test::Bencher) { let input = include_str!("../cases/600b_event_no_escape.json"); + b.bytes = input.len() as u64; b.iter(|| input.split('"').for_each(drop)) } @@ -261,5 +285,6 @@ fn read_600b_event_no_escape_split(b: &mut test::Bencher) { fn read_600b_event_no_escape_validate_utf8(b: &mut test::Bencher) { let input = include_bytes!("../cases/600b_event_no_escape.json"); + b.bytes = input.len() as u64; b.iter(|| str::from_utf8(input).unwrap()) } diff --git a/src/lib.rs b/src/lib.rs index 01c206a..d3dcc83 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -37,8 +37,8 @@ mod macros; mod std_ext; -mod unescape; pub mod de; +mod unescape; pub use de::Document; #[cfg(test)] diff --git a/src/std_ext.rs b/src/std_ext.rs index 80b0968..894e182 100644 --- a/src/std_ext.rs +++ b/src/std_ext.rs @@ -4,5 +4,5 @@ This module has some "standard" extensions used in the deserializer. These extensions follow the same layout as Rust's standard library. */ -pub(crate) mod char; pub(crate) mod arch; +pub(crate) mod char; diff --git a/src/std_ext/arch/aarch64.rs b/src/std_ext/arch/aarch64.rs index 817bf56..d96157d 100644 --- a/src/std_ext/arch/aarch64.rs +++ b/src/std_ext/arch/aarch64.rs @@ -1,7 +1,5 @@ #[cfg(any(target_feature = "neon", target_feature = "crc"))] -use std::{ - arch::aarch64::*, -}; +use std::arch::aarch64::*; #[target_feature(enable = "neon")] #[inline] @@ -31,6 +29,6 @@ pub unsafe fn vmovemask_u8(a: uint8x8_t) -> u8 { 0b0010_0000, 0b0100_0000, 0b1000_0000, - ]) + ]), )) } diff --git a/src/unescape.rs b/src/unescape.rs index d0ad9ec..16d2369 100644 --- a/src/unescape.rs +++ b/src/unescape.rs @@ -191,7 +191,7 @@ impl<'a> ScanFnInput<'a> { #[inline(always)] fn interest_unescape<'a, I: BorrowMut>>(mut i: I) { - let mut i = i.borrow_mut(); + let i = i.borrow_mut(); let escaped = i.scan.escape; i.scan.escape = !escaped; @@ -244,8 +244,10 @@ fn interest_unescape<'a, I: BorrowMut>>(mut i: I) { match i.scan.first_surrogate.take() { // if we had a surrogate pair, then attempt to map it to a multibyte Some(first) => { - let ch = crate::std_ext::char::try_from_utf16_surrogate_pair(first, code) - .map_err(|_| ())?; + let ch = crate::std_ext::char::try_from_utf16_surrogate_pair( + first, code, + ) + .map_err(|_| ())?; i.push_unescaped_char(ch); } // if we didn't have a surrogate pair,