Skip to content
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
2 changes: 1 addition & 1 deletion .github/workflows/benchmark.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ path = "examples/escape.rs"

[features]
force_aarch64_neon = [] # Force use of neon implementation on aarch64
codspeed = []

[[bench]]
name = "escape"
Expand Down
3 changes: 3 additions & 0 deletions benches/escape.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,15 @@ 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 {
black_box(v_jsonescape::escape(source).to_string());
}
})
});
#[cfg(not(feature = "codspeed"))]
c.bench_function(&format!("{} json-escape", prefix), |b| {
b.iter(|| {
for source in sources {
Expand All @@ -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 {
Expand Down
4 changes: 3 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<S: AsRef<str>>(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);
Expand Down Expand Up @@ -178,6 +179,7 @@ pub fn escape<S: AsRef<str>>(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<S: AsRef<str>>(input: S, output: &mut Vec<u8>) {
#[cfg(not(feature = "force_aarch64_neon"))]
use generic::escape_inner;

output.push(b'"');
Expand Down Expand Up @@ -208,7 +210,7 @@ pub fn escape_into<S: AsRef<str>>(input: S, output: &mut Vec<u8>) {
{
#[cfg(feature = "force_aarch64_neon")]
{
return aarch64::escape_neon(bytes, output);
aarch64::escape_neon(bytes, output);
}
#[cfg(not(feature = "force_aarch64_neon"))]
{
Expand Down
Loading