From 2b85b629723047defb5f84c79e87f936ca262540 Mon Sep 17 00:00:00 2001 From: SunDoge <384813529@qq.com> Date: Sat, 26 Aug 2023 15:59:53 +0800 Subject: [PATCH 1/2] add simdjson-rust --- Cargo.toml | 9 ++++++++- src/main.rs | 42 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 0a888ea..90fe574 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,15 +12,22 @@ rustc-serialize = { version = "0.3", optional = true } serde = { version = "1.0", features = ["derive"], optional = true } serde_json = { version = "1.0", optional = true } simd-json = { version = "0.10", optional = true } +simdjson-rust = { version = "0.3.0-alpha.2", optional = true } [features] default = ["performance", "all-libs", "all-files"] -all-libs = ["lib-serde", "lib-rustc-serialize", "lib-simd-json"] +all-libs = [ + "lib-serde", + # lib-rustc-serialize", + "lib-simd-json", + "lib-simdjson-rust" +] all-files = ["file-canada", "file-citm-catalog", "file-twitter"] performance = ["parse-dom", "stringify-dom", "parse-struct", "stringify-struct"] lib-serde = ["serde", "serde_json"] lib-simd-json = ["serde", "simd-json"] lib-rustc-serialize = ["rustc-serialize"] +lib-simdjson-rust = ["simdjson-rust"] file-canada = [] file-citm-catalog = [] file-twitter = [] diff --git a/src/main.rs b/src/main.rs index 4cd8c65..f89ee14 100644 --- a/src/main.rs +++ b/src/main.rs @@ -196,6 +196,42 @@ macro_rules! bench_file_simd_json { } } +#[cfg(feature = "lib-simdjson-rust")] +macro_rules! bench_file_simdjson_rust { + ( + path: $path:expr, + structure: $structure:ty, + ) => { + use simdjson_rust::prelude::*; + + let num_trials = num_trials().unwrap_or(256); + + print!("{:22}", $path); + io::stdout().flush().unwrap(); + + let contents = load_padded_string($path).unwrap(); + + #[cfg(feature = "parse-dom")] + { + use timer::Benchmark; + let mut benchmark = Benchmark::new(); + let mut parser = simdjson_rust::dom::Parser::default(); + for _ in 0..num_trials { + let mut timer = benchmark.start(); + let _parsed = parser.parse(&contents).unwrap(); + timer.stop(); + } + let dur = benchmark.min_elapsed(); + print!("{:6} MB/s", throughput(dur, contents.len())); + io::stdout().flush().unwrap(); + } + #[cfg(not(feature = "parse-dom"))] + print!(" "); + + println!(); + }; +} + fn main() { print!("{:>35}{:>24}", "DOM", "STRUCT"); @@ -226,6 +262,12 @@ fn main() { name: "simd-json", bench: bench_file_simd_json, } + + #[cfg(feature = "lib-simdjson-rust")] + bench! { + name: "simdjson-rust", + bench: bench_file_simdjson_rust, + } } #[cfg(all( From 93bb516654d3ed8418c6715f822dc0be39fa4e0a Mon Sep 17 00:00:00 2001 From: SunDoge <384813529@qq.com> Date: Sun, 27 Aug 2023 10:27:21 +0800 Subject: [PATCH 2/2] remove prelude --- src/main.rs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/main.rs b/src/main.rs index f89ee14..636d622 100644 --- a/src/main.rs +++ b/src/main.rs @@ -202,14 +202,12 @@ macro_rules! bench_file_simdjson_rust { path: $path:expr, structure: $structure:ty, ) => { - use simdjson_rust::prelude::*; - let num_trials = num_trials().unwrap_or(256); print!("{:22}", $path); io::stdout().flush().unwrap(); - let contents = load_padded_string($path).unwrap(); + let contents = simdjson_rust::padded_string::load_padded_string($path).unwrap(); #[cfg(feature = "parse-dom")] {