Skip to content
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

test: Str benchmarks #75

Merged
merged 3 commits into from
Feb 3, 2021
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
46 changes: 30 additions & 16 deletions benches/large_case.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,44 @@ use std::time::Duration;
extern crate criterion;
use self::criterion::*;

use pubgrub::package::Package;
use pubgrub::solver::{resolve, OfflineDependencyProvider};
use pubgrub::version::NumberVersion;
use pubgrub::version::{NumberVersion, SemanticVersion, Version};
use serde::de::Deserialize;
use std::hash::Hash;

fn bench<'a, P: Package + Deserialize<'a>, V: Version + Hash + Deserialize<'a>>(
b: &mut Bencher,
case: &'a str,
) {
let dependency_provider: OfflineDependencyProvider<P, V> = ron::de::from_str(&case).unwrap();

b.iter(|| {
for p in dependency_provider.packages() {
for n in dependency_provider.versions(p).unwrap() {
let _ = resolve(&dependency_provider, p.clone(), n.clone());
}
}
});
}

fn bench_nested(c: &mut Criterion) {
let mut group = c.benchmark_group("large_cases");
group.measurement_time(Duration::from_secs(20));

for case in std::fs::read_dir("test-examples").unwrap() {
let case = case.unwrap().path();

group.bench_function(
format!("{}", case.file_name().unwrap().to_string_lossy()),
|b| {
let s = std::fs::read_to_string(&case).unwrap();
let dependency_provider: OfflineDependencyProvider<u16, NumberVersion> =
ron::de::from_str(&s).unwrap();

b.iter(|| {
for &n in dependency_provider.versions(&0).unwrap() {
let _ = resolve(&dependency_provider, 0, n);
}
});
},
);
let name = case.file_name().unwrap().to_string_lossy();
let data = std::fs::read_to_string(&case).unwrap();
if name.ends_with("u16_NumberVersion.ron") {
group.bench_function(name, |b| {
bench::<u16, NumberVersion>(b, &data);
});
} else if name.ends_with("str_SemanticVersion.ron") {
group.bench_function(name, |b| {
bench::<&str, SemanticVersion>(b, &data);
});
}
}

group.finish();
Expand Down
40 changes: 40 additions & 0 deletions tests/proptest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -478,3 +478,43 @@ proptest! {
}
}
}

#[cfg(feature = "serde")]
#[test]
fn large_case() {
for case in std::fs::read_dir("test-examples").unwrap() {
let case = case.unwrap().path();
let name = case.file_name().unwrap().to_string_lossy();
eprintln!("{}", name);
let data = std::fs::read_to_string(&case).unwrap();
if name.ends_with("u16_NumberVersion.ron") {
let dependency_provider: OfflineDependencyProvider<u16, NumberVersion> =
ron::de::from_str(&data).unwrap();
let mut sat = SatResolve::new(&dependency_provider);
for p in dependency_provider.packages() {
for n in dependency_provider.versions(p).unwrap() {
if let Ok(s) = resolve(&dependency_provider, p.clone(), n.clone()) {
assert!(sat.sat_is_valid_solution(&s));
} else {
assert!(!sat.sat_resolve(p, &n));
}
}
}
} else if name.ends_with("str_SemanticVersion.ron") {
let dependency_provider: OfflineDependencyProvider<
&str,
pubgrub::version::SemanticVersion,
> = ron::de::from_str(&data).unwrap();
let mut sat = SatResolve::new(&dependency_provider);
for p in dependency_provider.packages() {
for n in dependency_provider.versions(p).unwrap() {
if let Ok(s) = resolve(&dependency_provider, p.clone(), n.clone()) {
assert!(sat.sat_is_valid_solution(&s));
} else {
assert!(!sat.sat_resolve(p, &n));
}
}
}
}
}
}