Skip to content

Update benchmarks and Rust #70

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jul 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,17 @@ Enabling this feature without `libc++` installed would cause compile error.

### Performance

Ada is fast. The benchmark below shows **3.34 times** faster URL parsing compared to `url`
Ada is fast. The benchmark below shows **3.49 times** faster URL parsing compared to `url`

```text
parse/ada_url time: [2.0790 µs 2.0812 µs 2.0835 µs]
thrpt: [369.84 MiB/s 370.25 MiB/s 370.65 MiB/s]
can_parse/ada_url time: [1.2109 µs 1.2121 µs 1.2133 µs]
thrpt: [635.09 MiB/s 635.75 MiB/s 636.38 MiB/s]

parse/url time: [6.9266 µs 6.9677 µs 7.0199 µs]
thrpt: [109.77 MiB/s 110.59 MiB/s 111.25 MiB/s]
parse/ada_url time: [2.0124 µs 2.0157 µs 2.0190 µs]
thrpt: [381.67 MiB/s 382.28 MiB/s 382.91 MiB/s]

parse/url time: [7.0530 µs 7.0597 µs 7.0666 µs]
thrpt: [109.04 MiB/s 109.15 MiB/s 109.25 MiB/s]
```

### Implemented traits
Expand Down
16 changes: 15 additions & 1 deletion bench/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,19 @@ pub fn parse_benchmark(c: &mut Criterion) {
group.finish();
}

criterion_group!(benches, parse_benchmark);
pub fn can_parse_benchmark(c: &mut Criterion) {
let mut group = c.benchmark_group("can_parse");
group.throughput(Throughput::Bytes(URLS.iter().map(|u| u.len() as u64).sum()));
group.bench_function("ada_url", |b| {
b.iter(|| {
URLS.iter().for_each(|url| {
let _ = ada_url::Url::can_parse(*black_box(url), None);
})
})
});
// TODO: Add `url` crate when it supports can_parse function.
group.finish();
}

criterion_group!(benches, parse_benchmark, can_parse_benchmark);
criterion_main!(benches);
2 changes: 1 addition & 1 deletion rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[toolchain]
channel = "1.77.0"
channel = "1.79.0"
profile = "default"
9 changes: 6 additions & 3 deletions src/ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ use core::ffi::{c_char, c_uint};
#[cfg(feature = "std")]
extern crate std;

#[cfg(feature = "std")]
use std::fmt::Display;

#[repr(C)]
pub struct ada_url {
_unused: [u8; 0],
Expand Down Expand Up @@ -42,9 +45,9 @@ impl AsRef<str> for ada_owned_string {
}

#[cfg(feature = "std")]
impl ToString for ada_owned_string {
fn to_string(&self) -> std::string::String {
self.as_ref().to_owned()
impl Display for ada_owned_string {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
write!(f, "{}", self.as_ref().to_owned())
}
}

Expand Down
Loading