Skip to content

Commit

Permalink
Update matchit benchmarks to v0.8.6
Browse files Browse the repository at this point in the history
  • Loading branch information
CathalMullan committed Jan 7, 2025
1 parent 9f06dec commit f3ed9c1
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 38 deletions.
2 changes: 1 addition & 1 deletion BENCHMARKING.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ All routers provide a way to return parameters as strings, but some delay the ac

## `matchit` inspired benches

In a router of 130 templates, benchmark matching 4 paths.
In a router of 130 templates, benchmark matching 130 paths.

| Library | Time | Alloc Count | Alloc Size | Dealloc Count | Dealloc Size |
|:-----------------|----------:|------------:|-----------:|--------------:|-------------:|
Expand Down
19 changes: 9 additions & 10 deletions benches/matchit_criterion.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
//! Benches sourced from `matchit` (MIT AND BSD-3-Clause)
//! <https://github.com/ibraheemdev/matchit/blob/v0.8.5/benches/bench.rs>
//! <https://github.com/ibraheemdev/matchit/blob/v0.8.6/benches/bench.rs>
use codspeed_criterion_compat::{black_box, criterion_group, criterion_main, Criterion};
use matchit_routes::paths;

pub mod matchit_routes;

Expand All @@ -23,7 +22,7 @@ fn matchit_benchmark(criterion: &mut Criterion) {
}

bencher.iter(|| {
for path in black_box(paths()) {
for path in black_box(routes!(literal)) {
let output = black_box(router.search(black_box(path)).unwrap());
let _parameters: Vec<(&str, &str)> =
black_box(output.parameters.iter().map(|p| (p.0, p.1)).collect());
Expand All @@ -39,7 +38,7 @@ fn matchit_benchmark(criterion: &mut Criterion) {
let router = router.finish();

bencher.iter(|| {
for path in black_box(paths()) {
for path in black_box(routes!(literal)) {
let mut path = actix_router::Path::new(path);
black_box(router.recognize(black_box(&mut path)).unwrap());
let _parameters: Vec<(&str, &str)> =
Expand All @@ -55,7 +54,7 @@ fn matchit_benchmark(criterion: &mut Criterion) {
}

bencher.iter(|| {
for path in black_box(paths()) {
for path in black_box(routes!(literal)) {
let output = black_box(router.at(black_box(path)).unwrap());
let _parameters: Vec<(&str, &str)> =
black_box(output.params.iter().map(|p| (p.0, p.1)).collect());
Expand All @@ -71,7 +70,7 @@ fn matchit_benchmark(criterion: &mut Criterion) {
let router = router.finish();

bencher.iter(|| {
for path in black_box(paths()) {
for path in black_box(routes!(literal)) {
let mut path = ntex_router::Path::new(path);
router.recognize(&mut path).unwrap();
let _parameters: Vec<(&str, &str)> =
Expand All @@ -87,7 +86,7 @@ fn matchit_benchmark(criterion: &mut Criterion) {
}

bencher.iter(|| {
for path in black_box(paths()) {
for path in black_box(routes!(literal)) {
let output = router.find(path).unwrap();
let _parameters: Vec<(&str, &str)> =
black_box(output.1.params_iter().map(|p| (p.0, p.1)).collect());
Expand All @@ -102,7 +101,7 @@ fn matchit_benchmark(criterion: &mut Criterion) {
}

bencher.iter(|| {
for path in black_box(paths()) {
for path in black_box(routes!(literal)) {
let output = router.recognize(path).unwrap();
let _parameters: Vec<(&str, &str)> =
black_box(output.params().iter().map(|p| (p.0, p.1)).collect());
Expand All @@ -117,7 +116,7 @@ fn matchit_benchmark(criterion: &mut Criterion) {
}

bencher.iter(|| {
for path in black_box(paths()) {
for path in black_box(routes!(literal)) {
let output = router.best_match(path).unwrap();
let _parameters: Vec<(&str, &str)> =
black_box(output.captures().iter().map(|p| (p.0, p.1)).collect());
Expand All @@ -132,7 +131,7 @@ fn matchit_benchmark(criterion: &mut Criterion) {
}

bencher.iter(|| {
for path in black_box(paths()) {
for path in black_box(routes!(literal)) {
let output = router.at(path).unwrap();
let _parameters: Vec<(&str, &str)> =
black_box(output.params.iter().map(|p| (p.0, p.1)).collect());
Expand Down
20 changes: 10 additions & 10 deletions benches/matchit_divan.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
//! Benches sourced from `matchit` (MIT AND BSD-3-Clause)
//! <https://github.com/ibraheemdev/matchit/blob/v0.8.5/benches/bench.rs>
//! <https://github.com/ibraheemdev/matchit/blob/v0.8.6/benches/bench.rs>
use codspeed_criterion_compat::black_box;
use divan::AllocProfiler;
use matchit_routes::paths;

pub mod matchit_routes;

Expand All @@ -17,12 +16,13 @@ fn main() {
#[divan::bench(name = "wayfind")]
fn wayfind(bencher: divan::Bencher<'_, '_>) {
let mut router = wayfind::Router::new();

for route in routes!(brackets) {
router.insert(route, true).unwrap();
}

bencher.bench(|| {
for path in black_box(paths()) {
for path in black_box(routes!(literal)) {
let output = black_box(router.search(black_box(path)).unwrap());
let _parameters: Vec<(&str, &str)> =
black_box(output.parameters.iter().map(|p| (p.0, p.1)).collect());
Expand All @@ -39,7 +39,7 @@ fn actix_router(bencher: divan::Bencher<'_, '_>) {
let router = router.finish();

bencher.bench(|| {
for path in black_box(paths()) {
for path in black_box(routes!(literal)) {
let mut path = actix_router::Path::new(path);
black_box(router.recognize(black_box(&mut path)).unwrap());
let _parameters: Vec<(&str, &str)> =
Expand All @@ -56,7 +56,7 @@ fn matchit(bencher: divan::Bencher<'_, '_>) {
}

bencher.bench(|| {
for path in black_box(paths()) {
for path in black_box(routes!(literal)) {
let output = black_box(router.at(black_box(path)).unwrap());
let _parameters: Vec<(&str, &str)> =
black_box(output.params.iter().map(|p| (p.0, p.1)).collect());
Expand All @@ -73,7 +73,7 @@ fn ntex_router(bencher: divan::Bencher<'_, '_>) {
let router = router.finish();

bencher.bench(|| {
for path in black_box(paths()) {
for path in black_box(routes!(literal)) {
let mut path = ntex_router::Path::new(path);
router.recognize(&mut path).unwrap();
let _parameters: Vec<(&str, &str)> =
Expand All @@ -90,7 +90,7 @@ fn path_tree(bencher: divan::Bencher<'_, '_>) {
}

bencher.bench(|| {
for path in black_box(paths()) {
for path in black_box(routes!(literal)) {
let output = router.find(path).unwrap();
let _parameters: Vec<(&str, &str)> =
black_box(output.1.params_iter().map(|p| (p.0, p.1)).collect());
Expand All @@ -106,7 +106,7 @@ fn route_recognizer(bencher: divan::Bencher<'_, '_>) {
}

bencher.bench(|| {
for path in black_box(paths()) {
for path in black_box(routes!(literal)) {
let output = router.recognize(path).unwrap();
let _parameters: Vec<(&str, &str)> =
black_box(output.params().iter().map(|p| (p.0, p.1)).collect());
Expand All @@ -122,7 +122,7 @@ fn routefinder(bencher: divan::Bencher<'_, '_>) {
}

bencher.bench(|| {
for path in black_box(paths()) {
for path in black_box(routes!(literal)) {
let output = router.best_match(path).unwrap();
let _parameters: Vec<(&str, &str)> =
black_box(output.captures().iter().map(|p| (p.0, p.1)).collect());
Expand All @@ -138,7 +138,7 @@ fn xitca_router(bencher: divan::Bencher<'_, '_>) {
}

bencher.bench(|| {
for path in black_box(paths()) {
for path in black_box(routes!(literal)) {
let output = router.at(path).unwrap();
let _parameters: Vec<(&str, &str)> =
black_box(output.params.iter().map(|p| (p.0, p.1)).collect());
Expand Down
26 changes: 10 additions & 16 deletions benches/matchit_routes.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,9 @@
#[must_use]
pub fn paths() -> impl IntoIterator<Item = &'static str> {
vec![
"/user/repos",
"/repos/rust-lang/rust/stargazers",
"/orgs/rust-lang/public_members/nikomatsakis",
"/repos/rust-lang/rust/releases/1.51.0",
]
}

#[macro_export]
macro_rules! routes {
(literal) => {{
routes!(finish => "p1", "p2", "p3", "p4")
}};

(colon) => {{
routes!(finish => ":p1", ":p2", ":p3", ":p4")
}};
Expand Down Expand Up @@ -79,13 +73,13 @@ macro_rules! routes {
concat!("/user/orgs"),
concat!("/orgs/", $p1),
concat!("/orgs/", $p1, "/members"),
concat!("/orgs/", $p1, "/members", $p2),
concat!("/orgs/", $p1, "/members/", $p2),
concat!("/orgs/", $p1, "/public_members"),
concat!("/orgs/", $p1, "/public_members/", $p2),
concat!("/orgs/", $p1, "/teams"),
concat!("/teams/", $p1),
concat!("/teams/", $p1, "/members"),
concat!("/teams/", $p1, "/members", $p2),
concat!("/teams/", $p1, "/members/", $p2),
concat!("/teams/", $p1, "/repos"),
concat!("/teams/", $p1, "/repos/", $p2, "/", $p3),
concat!("/user/teams"),
Expand Down Expand Up @@ -114,12 +108,12 @@ macro_rules! routes {
concat!("/repos/", $p1, "/", $p2, "/commits/", $p3),
concat!("/repos/", $p1, "/", $p2, "/readme"),
concat!("/repos/", $p1, "/", $p2, "/keys"),
concat!("/repos/", $p1, "/", $p2, "/keys", $p3),
concat!("/repos/", $p1, "/", $p2, "/keys/", $p3),
concat!("/repos/", $p1, "/", $p2, "/downloads"),
concat!("/repos/", $p1, "/", $p2, "/downloads", $p3),
concat!("/repos/", $p1, "/", $p2, "/downloads/", $p3),
concat!("/repos/", $p1, "/", $p2, "/forks"),
concat!("/repos/", $p1, "/", $p2, "/hooks"),
concat!("/repos/", $p1, "/", $p2, "/hooks", $p3),
concat!("/repos/", $p1, "/", $p2, "/hooks/", $p3),
concat!("/repos/", $p1, "/", $p2, "/releases"),
concat!("/repos/", $p1, "/", $p2, "/releases/", $p3),
concat!("/repos/", $p1, "/", $p2, "/releases/", $p3, "/assets"),
Expand All @@ -146,7 +140,7 @@ macro_rules! routes {
concat!("/users/", $p1, "/following"),
concat!("/user/following"),
concat!("/user/following/", $p1),
concat!("/users/", $p1, "/following", $p2),
concat!("/users/", $p1, "/following/", $p2),
concat!("/users/", $p1, "/keys"),
concat!("/user/keys"),
concat!("/user/keys/", $p1),
Expand Down
2 changes: 1 addition & 1 deletion src/node/search.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ impl<'r, T, S: NodeState> Node<'r, T, S> {
/// - static
/// - dynamic constrained
/// - dynamic
/// - wildcard contrained
/// - wildcard constrained
/// - wildcard
/// - end wildcard constrained
/// - wildcard
Expand Down

0 comments on commit f3ed9c1

Please sign in to comment.