mirror of https://github.com/fafhrd91/actix-web
feat: Add router bench for guard check failures
This commit is contained in:
parent
ffa95b7f60
commit
934f68ebf6
|
@ -1,6 +1,6 @@
|
|||
//! Based on https://github.com/ibraheemdev/matchit/blob/master/benches/bench.rs
|
||||
|
||||
use criterion::{black_box, criterion_group, criterion_main, Criterion};
|
||||
use criterion::{black_box, Criterion, criterion_group, criterion_main};
|
||||
|
||||
macro_rules! register {
|
||||
(colon) => {{
|
||||
|
@ -150,7 +150,7 @@ macro_rules! register {
|
|||
}};
|
||||
}
|
||||
|
||||
fn call() -> impl Iterator<Item = &'static str> {
|
||||
fn call() -> impl Iterator<Item=&'static str> {
|
||||
let arr = [
|
||||
"/authorizations",
|
||||
"/user/repos",
|
||||
|
@ -179,6 +179,15 @@ fn compare_routers(c: &mut Criterion) {
|
|||
});
|
||||
});
|
||||
|
||||
group.bench_function("actix_guard_failures", |b| {
|
||||
b.iter(|| {
|
||||
for route in call() {
|
||||
let mut path = actix_router::Path::new(route);
|
||||
black_box(actix.recognize_fn(&mut path, |_, _| false));
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
let regex_set = regex::RegexSet::new(register!(regex)).unwrap();
|
||||
group.bench_function("regex", |b| {
|
||||
b.iter(|| {
|
||||
|
|
|
@ -52,18 +52,18 @@ impl<T, U> Router<T, U> {
|
|||
R: Resource,
|
||||
F: FnMut(&R, &U) -> bool,
|
||||
{
|
||||
let mut matches = 0;
|
||||
let mut next_match_count = 1;
|
||||
for (rdef, val, ctx) in self.routes.iter() {
|
||||
match rdef.capture_match_info(resource) {
|
||||
None => {}
|
||||
Some(match_info) => {
|
||||
matches += 1;
|
||||
if check_fn(resource, ctx) {
|
||||
rdef.resolve_resource(resource, match_info);
|
||||
return Some((val, ResourceId(rdef.id())));
|
||||
} else if matches == self.max_path_conflicts {
|
||||
} else if next_match_count == self.max_path_conflicts {
|
||||
return None;
|
||||
}
|
||||
next_match_count += 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue