From 7607dab54a0a843b84800cecd804ed98e2f6d0ee Mon Sep 17 00:00:00 2001 From: Ali MJ Al-Nasrawy Date: Tue, 22 Mar 2022 20:09:40 +0300 Subject: [PATCH] split bench --- actix-router/Cargo.toml | 4 +++ actix-router/benches/quoter.rs | 50 ++++++++++++++++++++++++++++++++++ actix-router/benches/router.rs | 47 +------------------------------- actix-router/src/quoter.rs | 2 +- 4 files changed, 56 insertions(+), 47 deletions(-) create mode 100644 actix-router/benches/quoter.rs diff --git a/actix-router/Cargo.toml b/actix-router/Cargo.toml index 8ce4bdb43..76f39f631 100644 --- a/actix-router/Cargo.toml +++ b/actix-router/Cargo.toml @@ -37,3 +37,7 @@ percent-encoding = "2.1" [[bench]] name = "router" harness = false + +[[bench]] +name = "quoter" +harness = false diff --git a/actix-router/benches/quoter.rs b/actix-router/benches/quoter.rs new file mode 100644 index 000000000..c840f9ea2 --- /dev/null +++ b/actix-router/benches/quoter.rs @@ -0,0 +1,50 @@ +use criterion::{black_box, criterion_group, criterion_main, Criterion}; + +use std::borrow::Cow; + +fn compare_quoters(c: &mut Criterion) { + let mut group = c.benchmark_group("Compare Quoters"); + + let quoter = actix_router::Quoter::new(b"", b""); + let path_quoted = (0..=0x7f).map(|c| format!("%{:02X}", c)).collect::(); + let path_unquoted = ('\u{00}'..='\u{7f}').collect::(); + + group.bench_function("quoter_unquoted", |b| { + b.iter(|| { + for _ in 0..10 { + black_box(quoter.requote(path_unquoted.as_bytes())); + } + }); + }); + + group.bench_function("percent_encode_unquoted", |b| { + b.iter(|| { + for _ in 0..10 { + let decode = percent_encoding::percent_decode(path_unquoted.as_bytes()); + black_box(Into::>::into(decode)); + } + }); + }); + + group.bench_function("quoter_quoted", |b| { + b.iter(|| { + for _ in 0..10 { + black_box(quoter.requote(path_quoted.as_bytes())); + } + }); + }); + + group.bench_function("percent_encode_quoted", |b| { + b.iter(|| { + for _ in 0..10 { + let decode = percent_encoding::percent_decode(path_quoted.as_bytes()); + black_box(Into::>::into(decode)); + } + }); + }); + + group.finish(); +} + +criterion_group!(benches, compare_quoters); +criterion_main!(benches); diff --git a/actix-router/benches/router.rs b/actix-router/benches/router.rs index e0f49378e..6f6b67b48 100644 --- a/actix-router/benches/router.rs +++ b/actix-router/benches/router.rs @@ -2,8 +2,6 @@ use criterion::{black_box, criterion_group, criterion_main, Criterion}; -use std::borrow::Cow; - macro_rules! register { (colon) => {{ register!(finish => ":p1", ":p2", ":p3", ":p4") @@ -164,49 +162,6 @@ fn call() -> impl Iterator { IntoIterator::into_iter(arr) } -fn compare_quoters(c: &mut Criterion) { - let mut group = c.benchmark_group("Compare Quoters"); - - let quoter = actix_router::Quoter::new(b"", b""); - let path = (0..=127).map(|c| format!("%{:02X}", c)).collect::(); - - group.bench_function("quoter_x", |b| { - b.iter(|| { - for route in call() { - black_box(quoter.requote(route.as_bytes())); - } - }); - }); - - group.bench_function("percent_encode", |b| { - b.iter(|| { - for route in call() { - let decode = percent_encoding::percent_decode(route.as_bytes()); - black_box(Into::>::into(decode)); - } - }); - }); - - group.bench_function("quoter_x_stat", |b| { - b.iter(|| { - for _ in 0..10 { - black_box(quoter.requote(path.as_bytes())); - } - }); - }); - - group.bench_function("percent_encode_stat", |b| { - b.iter(|| { - for _ in 0..10 { - let decode = percent_encoding::percent_decode(path.as_bytes()); - black_box(Into::>::into(decode)); - } - }); - }); - - group.finish(); -} - fn compare_routers(c: &mut Criterion) { let mut group = c.benchmark_group("Compare Routers"); @@ -236,5 +191,5 @@ fn compare_routers(c: &mut Criterion) { group.finish(); } -criterion_group!(benches, compare_quoters); +criterion_group!(benches, compare_routers); criterion_main!(benches); diff --git a/actix-router/src/quoter.rs b/actix-router/src/quoter.rs index bdfb0f993..625e3fd63 100644 --- a/actix-router/src/quoter.rs +++ b/actix-router/src/quoter.rs @@ -46,7 +46,7 @@ impl Quoter { for i in 0..val.len() { if let (prev, [b'%', p1, p2, rem @ ..]) = val.split_at(i) { if let Some(ch) = hex_pair_to_char(*p1, *p2) - // ingore protected ascii bytes + // ignore protected ascii bytes .filter(|&ch| !(ch < 128 && bit_at(&self.protected_table, ch))) { *val = rem;