diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml index 01982fd..5a04b0a 100644 --- a/.github/workflows/benchmark.yml +++ b/.github/workflows/benchmark.yml @@ -44,7 +44,7 @@ jobs: tool: cargo-codspeed - name: Build benchmark - run: cargo codspeed build + run: cargo codspeed build --features codspeed - name: Run benchmark uses: CodSpeedHQ/action@v4 diff --git a/Cargo.toml b/Cargo.toml index 77690b1..5c3a16f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -18,6 +18,7 @@ path = "examples/escape.rs" [features] force_aarch64_neon = [] # Force use of neon implementation on aarch64 +codspeed = [] [[bench]] name = "escape" diff --git a/benches/escape.rs b/benches/escape.rs index 8a69a18..ef36350 100644 --- a/benches/escape.rs +++ b/benches/escape.rs @@ -45,6 +45,7 @@ fn run_benchmarks(c: &mut Criterion, sources: &[String], prefix: &str) { } }) }); + #[cfg(not(feature = "codspeed"))] c.bench_function(&format!("{} escape v_jsonescape", prefix), |b| { b.iter(|| { for source in sources { @@ -52,6 +53,7 @@ fn run_benchmarks(c: &mut Criterion, sources: &[String], prefix: &str) { } }) }); + #[cfg(not(feature = "codspeed"))] c.bench_function(&format!("{} json-escape", prefix), |b| { b.iter(|| { for source in sources { @@ -66,6 +68,7 @@ fn run_benchmarks(c: &mut Criterion, sources: &[String], prefix: &str) { } }) }); + #[cfg(not(feature = "codspeed"))] c.bench_function(&format!("{} serde_json", prefix), |b| { b.iter(|| { for source in sources { diff --git a/src/lib.rs b/src/lib.rs index 1fe6e58..0dbdc3e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -119,6 +119,7 @@ pub use generic::{escape_generic, escape_into_generic}; /// Main entry point for JSON string escaping with SIMD acceleration /// If the platform is supported, the SIMD path will be used. Otherwise, the generic fallback will be used. pub fn escape>(input: S) -> String { + #[cfg(not(feature = "force_aarch64_neon"))] use generic::escape_inner; let mut result = Vec::with_capacity(input.as_ref().len() + input.as_ref().len() / 2 + 2); @@ -178,6 +179,7 @@ pub fn escape>(input: S) -> String { /// Main entry point for JSON string escaping with SIMD acceleration /// If the platform is supported, the SIMD path will be used. Otherwise, the generic fallback will be used. pub fn escape_into>(input: S, output: &mut Vec) { + #[cfg(not(feature = "force_aarch64_neon"))] use generic::escape_inner; output.push(b'"'); @@ -208,7 +210,7 @@ pub fn escape_into>(input: S, output: &mut Vec) { { #[cfg(feature = "force_aarch64_neon")] { - return aarch64::escape_neon(bytes, output); + aarch64::escape_neon(bytes, output); } #[cfg(not(feature = "force_aarch64_neon"))] {