Skip to content

Commit

Permalink
fix bincode versioning (#105)
Browse files Browse the repository at this point in the history
* properly space datetime in the benchmark output file names

* when we bench multiple versions of the same crate, make it possible to look them up by semver from the config

* suppress a cargo-metadata warning by specifying the format
  • Loading branch information
mumbleskates authored Mar 9, 2025
1 parent 9afce70 commit df83a6a
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 14 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ enum-iterator = "0.8"
fixed-map = { version = "0.9", default-features = false }
regex = "1.11"
schema = { path = "tools/schema" }
semver = "1.0.26"
serde = "1.0"
serde_json = "1.0"
stylist = { version = "0.12", default-features = false }
Expand Down
16 changes: 8 additions & 8 deletions tools/bencher/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ fn main() {

let metadata_path = NamedTempFile::new().unwrap().into_temp_path();
let metadata = Command::new("cargo")
.args(["metadata"])
.args(["metadata", "--format-version", "1"])
.output()
.unwrap()
.stdout;
Expand All @@ -32,13 +32,13 @@ fn main() {

let mut bench_path = PathBuf::from("benchmark_results");
bench_path.push(format!(
"{}-{}-{}_{}-{}-{}",
now.year(),
now.month() as usize,
now.day(),
now.hour(),
now.minute(),
now.second(),
"{yr}-{mon:02}-{day:02}_{hr:02}-{min:02}-{sec:02}",
yr = now.year(),
mon = now.month() as usize,
day = now.day(),
hr = now.hour(),
min = now.minute(),
sec = now.second(),
));

let mut log_path = bench_path.clone();
Expand Down
4 changes: 2 additions & 2 deletions tools/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@
"features": {
"bincode1": {
"name": "bincode",
"version": "1.3.3"
"version": "1"
},
"bincode": {
"name": "bincode",
"version": "2.0.0-rc"
"version": "2"
}
}
}
1 change: 1 addition & 0 deletions tools/parser/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@ cargo_metadata.workspace = true
clap = { workspace = true, features = ["derive"] }
regex.workspace = true
schema.workspace = true
semver.workspace = true
serde = { workspace = true, features = ["derive"] }
serde_json.workspace = true
29 changes: 25 additions & 4 deletions tools/parser/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,20 +115,41 @@ fn main() {

fn find_package_id(feature: &str, config: &Config, metadata: &Metadata) -> PackageId {
if let Some(package_id) = config.features.get(feature) {
package_id.clone()
PackageId {
name: package_id.name.clone(),
version: find_package_version(
&package_id.name,
Some(
package_id
.version
.parse()
.expect("invalid version spec in config"),
),
metadata,
),
}
} else {
PackageId {
name: feature.to_string(),
version: find_package_version(feature, metadata),
version: find_package_version(feature, None, metadata),
}
}
}

fn find_package_version(name: &str, metadata: &Metadata) -> String {
fn find_package_version(
name: &str,
version_req: Option<semver::VersionReq>,
metadata: &Metadata,
) -> String {
metadata
.packages
.iter()
.find(|pkg| pkg.name == name)
.find(|pkg| {
pkg.name == name
&& version_req
.as_ref()
.map_or(true, |req| req.matches(&pkg.version))
})
.unwrap()
.version
.to_string()
Expand Down

0 comments on commit df83a6a

Please sign in to comment.