Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

display bench throughput, fix build #8

Merged
merged 2 commits into from
Sep 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions benches/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}

Expand All @@ -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) })
}

Expand All @@ -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();

Expand All @@ -40,13 +43,15 @@ 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))
}

#[bench]
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
Expand All @@ -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
Expand All @@ -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();
Expand All @@ -78,20 +85,23 @@ 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())
}

#[bench]
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))
}

#[bench]
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())
}

Expand All @@ -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())
}

Expand All @@ -110,13 +121,15 @@ 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())
}

#[bench]
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);

Expand All @@ -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();

Expand Down Expand Up @@ -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())
}

Expand All @@ -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())
}

Expand All @@ -195,27 +211,31 @@ 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))
}

#[bench]
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))
}

#[bench]
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))
}

#[bench]
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
Expand All @@ -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
Expand All @@ -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();
Expand All @@ -247,19 +269,22 @@ 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())
}

#[bench]
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))
}

#[bench]
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())
}
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ mod macros;

mod std_ext;

mod unescape;
pub mod de;
mod unescape;
pub use de::Document;

#[cfg(test)]
Expand Down
2 changes: 1 addition & 1 deletion src/std_ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
6 changes: 2 additions & 4 deletions src/std_ext/arch/aarch64.rs
Original file line number Diff line number Diff line change
@@ -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]
Expand Down Expand Up @@ -31,6 +29,6 @@ pub unsafe fn vmovemask_u8(a: uint8x8_t) -> u8 {
0b0010_0000,
0b0100_0000,
0b1000_0000,
])
]),
))
}
8 changes: 5 additions & 3 deletions src/unescape.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ impl<'a> ScanFnInput<'a> {

#[inline(always)]
fn interest_unescape<'a, I: BorrowMut<ScanFnInput<'a>>>(mut i: I) {
let mut i = i.borrow_mut();
let i = i.borrow_mut();

let escaped = i.scan.escape;
i.scan.escape = !escaped;
Expand Down Expand Up @@ -244,8 +244,10 @@ fn interest_unescape<'a, I: BorrowMut<ScanFnInput<'a>>>(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,
Expand Down