#![feature(test)]
extern crate httprouter;
extern crate test;
use httprouter::path::*;
use test::Bencher;
fn clean_tests() -> Vec<(&'static str, &'static str)> {
vec![
("/", "/"),
("/abc", "/abc"),
("/a/b/c", "/a/b/c"),
("/abc/", "/abc/"),
("/a/b/c/", "/a/b/c/"),
("", "/"),
("a/", "/a/"),
("abc", "/abc"),
("abc/def", "/abc/def"),
("a/b/c", "/a/b/c"),
("//", "/"),
("/abc//", "/abc/"),
("/abc/def//", "/abc/def/"),
("/a/b/c//", "/a/b/c/"),
("/abc//def//ghi", "/abc/def/ghi"),
("//abc", "/abc"),
("///abc", "/abc"),
("//abc//", "/abc/"),
(".", "/"),
("./", "/"),
("/abc/./def", "/abc/def"),
("/./abc/def", "/abc/def"),
("/abc/.", "/abc/"),
("..", "/"),
("../", "/"),
("../../", "/"),
("../..", "/"),
("../../abc", "/abc"),
("/abc/def/ghi/../jkl", "/abc/def/jkl"),
("/abc/def/../ghi/../jkl", "/abc/jkl"),
("/abc/def/..", "/abc"),
("/abc/def/../..", "/"),
("/abc/def/../../..", "/"),
("/abc/def/../../..", "/"),
("/abc/def/../../../ghi/jkl/../../../mno", "/mno"),
("abc/./../def", "/def"),
("abc//./../def", "/def"),
("abc/../../././../def", "/def"),
]
}
#[bench]
fn test_path_clean(b: &mut Bencher) {
let tests = clean_tests();
b.iter(|| {
for test in &tests {
test::black_box(clean(test.0));
test::black_box(clean(test.1));
}
});
}
#[bench]
fn test_path_clean_long(b: &mut Bencher) {
let mut test_paths: Vec<(String, String)> = Vec::new();
for i in 1..1234 {
let ss = "a".repeat(i);
let correct_path = format!("{}{}", "/", ss);
test_paths.push((correct_path.clone(), correct_path.clone()));
test_paths.push((ss.clone(), correct_path.clone()));
test_paths.push((format!("{}{}", "//", ss), correct_path.clone()));
test_paths.push((format!("{}{}{}", "//", ss, "/b/.."), correct_path.clone()));
}
b.iter(|| {
for test in &test_paths {
test::black_box(clean(&test.0));
test::black_box(clean(&test.1));
}
});
}