Skip to content

Commit

Permalink
perf: use capacity_builder::FastDisplay (#42)
Browse files Browse the repository at this point in the history
  • Loading branch information
dsherret authored Dec 18, 2024
1 parent 8549620 commit d03466c
Show file tree
Hide file tree
Showing 8 changed files with 519 additions and 126 deletions.
227 changes: 221 additions & 6 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,13 @@ serde = { version = "1.0.130", features = ["derive", "rc"] }
thiserror = "2"
url = "2.5.3"
deno_error = "0.5.1"
capacity_builder = "0.4.0"

[dev-dependencies]
divan = "0.1.17"
pretty_assertions = "1.0.0"
serde_json = { version = "1.0.67", features = ["preserve_order"] }

[[bench]]
name = "bench"
harness = false
65 changes: 65 additions & 0 deletions benches/bench.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
fn main() {
// Run registered benchmarks.
divan::main();
}

mod package_req {
use deno_semver::package::PackageReq;

#[divan::bench(sample_size = 1000)]
fn from_str_loose() -> usize {
PackageReq::from_str_loose("@deno/[email protected]")
.unwrap()
.name
.len()
}

#[divan::bench(sample_size = 1000)]
fn to_string_normalized() -> usize {
PackageReq::from_str_loose("@deno/[email protected]")
.unwrap()
.to_string_normalized()
.len()
}
}

mod version {
use deno_semver::Version;

#[divan::bench(sample_size = 1000)]
fn to_string() -> usize {
version().to_string().len()
}

#[divan::bench(sample_size = 1000)]
fn to_string_display() -> usize {
format!("{}", version()).len()
}

fn version() -> Version {
Version::parse_from_npm("1.1.1-pre").unwrap()
}
}

mod version_req {
use deno_semver::VersionReq;

#[divan::bench(sample_size = 1000)]
fn to_string() -> usize {
version_req().to_string().len()
}

#[divan::bench(sample_size = 1000)]
fn to_string_display() -> usize {
format!("{}", version_req()).len()
}

#[divan::bench(sample_size = 1000)]
fn to_string_normalized() -> usize {
version_req().to_string_normalized().len()
}

fn version_req() -> VersionReq {
VersionReq::parse_from_npm("^1.1.1-pre").unwrap()
}
}
Loading

0 comments on commit d03466c

Please sign in to comment.