| 1 |
use codspeed_criterion_compat::{criterion_group, criterion_main, Criterion}; |
| 2 |
use oxiri::{Iri, IriRef}; |
| 3 |
|
| 4 |
fn abs_examples() -> &'static [&'static str] { |
| 5 |
&[ |
| 6 |
"file://foo", |
| 7 |
"ftp://ftp.is.co.za/rfc/rfc1808.txt", |
| 8 |
"http://www.ietf.org/rfc/rfc2396.txt", |
| 9 |
|
| 10 |
"mailto:[email protected]", |
| 11 |
"news:comp.infosystems.www.servers.unix", |
| 12 |
"tel:+1-816-555-1212", |
| 13 |
"telnet://192.0.2.16:80/", |
| 14 |
"urn:oasis:names:specification:docbook:dtd:xml:4.1.2", |
| 15 |
"http://example.com", |
| 16 |
"http://example.com/", |
| 17 |
"http://example.com/foo", |
| 18 |
"http://example.com/foo/bar", |
| 19 |
"http://example.com/foo/bar/", |
| 20 |
"http://example.com/foo/bar?q=1&r=2", |
| 21 |
"http://example.com/foo/bar/?q=1&r=2", |
| 22 |
"http://example.com#toto", |
| 23 |
"http://example.com/#toto", |
| 24 |
"http://example.com/foo#toto", |
| 25 |
"http://example.com/foo/bar#toto", |
| 26 |
"http://example.com/foo/bar/#toto", |
| 27 |
"http://example.com/foo/bar?q=1&r=2#toto", |
| 28 |
"http://example.com/foo/bar/?q=1&r=2#toto", |
| 29 |
"http://example.com/foo/bar/.././baz", |
| 30 |
] |
| 31 |
} |
| 32 |
|
| 33 |
fn iri_parse(c: &mut Criterion) { |
| 34 |
c.bench_function("Iri::parse", |b| { |
| 35 |
b.iter(|| { |
| 36 |
for iri in abs_examples().iter() { |
| 37 |
Iri::parse(*iri).unwrap(); |
| 38 |
} |
| 39 |
}) |
| 40 |
}); |
| 41 |
c.bench_function("Iri::parse_unchecked", |b| { |
| 42 |
b.iter(|| { |
| 43 |
for iri in abs_examples().iter() { |
| 44 |
Iri::parse_unchecked(*iri); |
| 45 |
} |
| 46 |
}) |
| 47 |
}); |
| 48 |
} |
| 49 |
|
| 50 |
fn iri_parse_relative(c: &mut Criterion) { |
| 51 |
c.bench_function("IriRef::parse", |b| { |
| 52 |
b.iter(|| { |
| 53 |
for iri in abs_examples().iter() { |
| 54 |
IriRef::parse(*iri).unwrap(); |
| 55 |
} |
| 56 |
}) |
| 57 |
}); |
| 58 |
c.bench_function("IriRef::parse_unchecked", |b| { |
| 59 |
b.iter(|| { |
| 60 |
for iri in abs_examples().iter() { |
| 61 |
IriRef::parse_unchecked(*iri); |
| 62 |
} |
| 63 |
}) |
| 64 |
}); |
| 65 |
} |
| 66 |
|
| 67 |
fn iri_resolve(c: &mut Criterion) { |
| 68 |
let examples = [ |
| 69 |
"g:h", |
| 70 |
"g", |
| 71 |
"g/", |
| 72 |
"/g", |
| 73 |
"//g", |
| 74 |
"?y", |
| 75 |
"g?y", |
| 76 |
"#s", |
| 77 |
"g#s", |
| 78 |
"g?y#s", |
| 79 |
";x", |
| 80 |
"g;x", |
| 81 |
"g;x?y#s", |
| 82 |
"", |
| 83 |
".", |
| 84 |
"./", |
| 85 |
"./g", |
| 86 |
"..", |
| 87 |
"../", |
| 88 |
"../g", |
| 89 |
"../..", |
| 90 |
"../../", |
| 91 |
"../../g", |
| 92 |
"../../../g", |
| 93 |
"../../../../g", |
| 94 |
"/./g", |
| 95 |
"/../g", |
| 96 |
"g.", |
| 97 |
".g", |
| 98 |
"g..", |
| 99 |
"..g", |
| 100 |
"./../g", |
| 101 |
"./g/.", |
| 102 |
"g/./h", |
| 103 |
"g/../h", |
| 104 |
"g;x=1/./y", |
| 105 |
"g;x=1/../y", |
| 106 |
"g?y/./x", |
| 107 |
"g?y/../x", |
| 108 |
"g#s/./x", |
| 109 |
"g#s/../x", |
| 110 |
"http:g", |
| 111 |
"./g:h", |
| 112 |
]; |
| 113 |
|
| 114 |
let base = Iri::parse("http://a/b/c/d;p?q").unwrap(); |
| 115 |
|
| 116 |
let mut buf = String::new(); |
| 117 |
c.bench_function("Iri::resolve_into", |b| { |
| 118 |
b.iter(|| { |
| 119 |
for relative in examples.iter() { |
| 120 |
buf.clear(); |
| 121 |
base.resolve_into(relative, &mut buf).unwrap(); |
| 122 |
} |
| 123 |
}) |
| 124 |
}); |
| 125 |
c.bench_function("Iri::resolve_into_unchecked", |b| { |
| 126 |
b.iter(|| { |
| 127 |
for relative in examples.iter() { |
| 128 |
buf.clear(); |
| 129 |
base.resolve_into_unchecked(relative, &mut buf); |
| 130 |
} |
| 131 |
}) |
| 132 |
}); |
| 133 |
} |
| 134 |
|
| 135 |
fn iri_relativize(c: &mut Criterion) { |
| 136 |
let base = Iri::parse("http://a/b/c/d;p?q").unwrap(); |
| 137 |
let examples = [ |
| 138 |
"g:h", |
| 139 |
"g", |
| 140 |
"g/", |
| 141 |
"/g", |
| 142 |
"//g", |
| 143 |
"?y", |
| 144 |
"g?y", |
| 145 |
"#s", |
| 146 |
"g#s", |
| 147 |
"g?y#s", |
| 148 |
";x", |
| 149 |
"g;x", |
| 150 |
"g;x?y#s", |
| 151 |
"", |
| 152 |
".", |
| 153 |
"./", |
| 154 |
"./g", |
| 155 |
"..", |
| 156 |
"../", |
| 157 |
"../g", |
| 158 |
"../..", |
| 159 |
"../../", |
| 160 |
"../../g", |
| 161 |
"../../../g", |
| 162 |
"../../../../g", |
| 163 |
"/./g", |
| 164 |
"/../g", |
| 165 |
"g.", |
| 166 |
".g", |
| 167 |
"g..", |
| 168 |
"..g", |
| 169 |
"./../g", |
| 170 |
"./g/.", |
| 171 |
"g/./h", |
| 172 |
"g/../h", |
| 173 |
"g;x=1/./y", |
| 174 |
"g;x=1/../y", |
| 175 |
"g?y/./x", |
| 176 |
"g?y/../x", |
| 177 |
"g#s/./x", |
| 178 |
"g#s/../x", |
| 179 |
"http:g", |
| 180 |
"./g:h", |
| 181 |
] |
| 182 |
.into_iter() |
| 183 |
.map(|iri| base.resolve(iri).unwrap()) |
| 184 |
.collect::<Vec<_>>(); |
| 185 |
|
| 186 |
c.bench_function("Iri::relativize", |b| { |
| 187 |
b.iter(|| { |
| 188 |
for iri in &examples { |
| 189 |
base.relativize(iri).unwrap(); |
| 190 |
} |
| 191 |
}) |
| 192 |
}); |
| 193 |
} |
| 194 |
|
| 195 |
criterion_group!( |
| 196 |
iri, |
| 197 |
iri_parse, |
| 198 |
iri_parse_relative, |
| 199 |
iri_resolve, |
| 200 |
iri_relativize |
| 201 |
); |
| 202 |
|
| 203 |
criterion_main!(iri); |