From f8ea1a6b4c403ab0ea4d62670c6770796f14e8d1 Mon Sep 17 00:00:00 2001 From: Aumetra Weisman Date: Tue, 17 Dec 2024 12:35:21 +0100 Subject: [PATCH] add basic auth bench --- lib/komainu/Cargo.toml | 4 ++++ lib/komainu/benches/basic_auth.rs | 21 +++++++++++++++++++++ 2 files changed, 25 insertions(+) create mode 100644 lib/komainu/benches/basic_auth.rs diff --git a/lib/komainu/Cargo.toml b/lib/komainu/Cargo.toml index 01a7e7a85..0990e3824 100644 --- a/lib/komainu/Cargo.toml +++ b/lib/komainu/Cargo.toml @@ -5,6 +5,10 @@ edition.workspace = true version.workspace = true license = "MIT OR Apache-2.0" +[[bench]] +name = "basic_auth" +harness = false + [[bench]] name = "pkce" harness = false diff --git a/lib/komainu/benches/basic_auth.rs b/lib/komainu/benches/basic_auth.rs new file mode 100644 index 000000000..90971a19e --- /dev/null +++ b/lib/komainu/benches/basic_auth.rs @@ -0,0 +1,21 @@ +use divan::{black_box, black_box_drop}; +use komainu::extractor::BasicAuth; + +#[divan::bench] +fn rfc_value(b: divan::Bencher<'_, '_>) { + let mut map = http::HeaderMap::new(); + map.insert( + http::header::AUTHORIZATION, + http::HeaderValue::from_static("Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ=="), + ); + + b.bench(|| { + let auth = BasicAuth::extract(black_box(&map)).unwrap(); + black_box_drop((auth.username(), auth.password())); + auth + }); +} + +fn main() { + divan::main(); +}