Skip to content

Commit

Permalink
Add bench for drop and without drop
Browse files Browse the repository at this point in the history
  • Loading branch information
dsherret committed Dec 20, 2024
1 parent 1715c98 commit d66a03e
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions benches/bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,21 @@ mod deserialization {

#[divan::bench]
fn packument(bencher: divan::Bencher) {
let text = get_next_packument_text();
bencher.bench_local(|| {
let value = serde_json::from_str::<NpmPackageInfo>(&text).unwrap();
value.name.len()
});
}

#[divan::bench]
fn packument_no_drop(bencher: divan::Bencher) {
let text = get_next_packument_text();
bencher
.bench_local(|| serde_json::from_str::<NpmPackageInfo>(&text).unwrap());
}

fn get_next_packument_text() -> String {
build_rt().block_on(async {
// ensure the fs cache is populated
let _ = RealBenchRegistryApi::default()
Expand All @@ -29,11 +44,7 @@ mod deserialization {
.unwrap();
});

let text =
std::fs::read_to_string(packument_cache_filepath("next")).unwrap();
bencher.bench_local(|| {
serde_json::from_str::<Arc<NpmPackageInfo>>(&text).unwrap()
});
std::fs::read_to_string(packument_cache_filepath("next")).unwrap()
}
}

Expand Down

0 comments on commit d66a03e

Please sign in to comment.