Skip to content

Commit cef4c04

Browse files
committed
feat: reduce string allocations
1 parent d3cd844 commit cef4c04

File tree

5 files changed

+197
-59
lines changed

5 files changed

+197
-59
lines changed

Cargo.lock

Lines changed: 67 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,15 @@ repository = "https://github.com/ada-url/rust"
99
license = "MIT AND APACHE-2.0"
1010
exclude = [".github"]
1111

12+
[[bench]]
13+
name = "parse"
14+
path = "bench/parse.rs"
15+
1216
[dependencies]
1317
thiserror = "1"
1418

19+
[dev-dependencies]
20+
url = "2" # Used by benchmarks
21+
1522
[build-dependencies]
1623
cc = { version = "1.0", features = ["parallel"] }

bench/parse.rs

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#![feature(test)]
2+
3+
extern crate test;
4+
5+
// Taken from https://github.com/Brooooooklyn/ada-url/blob/main/ada/bench/parse.rs
6+
7+
use ada_url::Url;
8+
use test::{black_box, Bencher};
9+
10+
const URL: &[&str] = &[
11+
"https://www.google.com/",
12+
"webhp?hl=en&ictx=2&sa=X&ved=0ahUKEwil_",
13+
"oSxzJj8AhVtEFkFHTHnCGQQPQgI",
14+
"https://support.google.com/websearch/",
15+
"?p=ws_results_help&hl=en-CA&fg=1",
16+
"https://en.wikipedia.org/wiki/Dog#Roles_with_humans",
17+
"https://www.tiktok.com/@aguyandagolden/video/7133277734310038830",
18+
"https://business.twitter.com/en/help/troubleshooting/",
19+
"how-twitter-ads-work.html?ref=web-twc-ao-gbl-adsinfo&utm_source=twc&utm_",
20+
"medium=web&utm_campaign=ao&utm_content=adsinfo",
21+
"https://images-na.ssl-images-amazon.com/images/I/",
22+
"41Gc3C8UysL.css?AUIClients/AmazonGatewayAuiAssets",
23+
"https://www.reddit.com/?after=t3_zvz1ze",
24+
"https://www.reddit.com/login/?dest=https%3A%2F%2Fwww.reddit.com%2F",
25+
"postgresql://other:9818274x1!!@localhost:5432/",
26+
"otherdb?connect_timeout=10&application_name=myapp",
27+
"http://192.168.1.1", // ipv4
28+
"http://[2606:4700:4700::1111]", // ipv6
29+
];
30+
31+
#[bench]
32+
fn ada_parse(b: &mut Bencher) {
33+
b.iter(|| {
34+
URL.iter().for_each(|url| {
35+
let _ = black_box(Url::parse(url, None));
36+
});
37+
});
38+
}
39+
40+
#[bench]
41+
fn servo_parse(b: &mut Bencher) {
42+
b.iter(|| {
43+
URL.iter().for_each(|url| {
44+
let _ = black_box(url::Url::parse(url));
45+
});
46+
});
47+
}

build.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use std::env;
22

3+
// Taken from https://github.com/Brooooooklyn/ada-url/blob/main/ada/build.rs
34
fn main() {
45
println!("cargo:rerun-if-changed=deps/ada.cpp");
56
println!("cargo:rerun-if-changed=deps/ada.h");

0 commit comments

Comments
 (0)