Skip to content

Commit

Permalink
Fix ok_or which used format_err, causing perf problems with debug…
Browse files Browse the repository at this point in the history
… builds
  • Loading branch information
ohadravid committed Jun 11, 2019
1 parent 80201ac commit 79738c3
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "wmi"
version = "0.4.3"
version = "0.4.4"
authors = ["Ohad Ravid <[email protected]>"]
edition = "2018"
license = "MIT OR Apache-2.0"
Expand Down
20 changes: 20 additions & 0 deletions src/benches/benchmark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,16 @@ pub struct ProcessExecutable {
pub Dependent: String,
}

#[derive(Serialize, Deserialize, Debug)]
#[serde(rename = "Win32_Service")]
pub struct Service {
pub Name: String,
pub DisplayName: String,
pub PathName: Option<String>,
pub State: String,
pub Started: bool,
}

fn get_accounts(con: &WMIConnection) {
let accounts: Vec<Account> = con.query().unwrap();
}
Expand Down Expand Up @@ -94,6 +104,10 @@ pub fn get_modules(con: &WMIConnection) {
let execs: Vec<ProcessExecutable> = con.query().unwrap();
}

fn get_services(con: &WMIConnection) {
let services: Vec<Service> = con.query().unwrap();
}

fn criterion_benchmark(c: &mut Criterion) {
// baseline: 41ms
c.bench_function("get_accounts", |b| {
Expand Down Expand Up @@ -137,6 +151,12 @@ fn criterion_benchmark(c: &mut Criterion) {
let wmi_con = WMIConnection::new(COMLibrary::new().unwrap().into()).unwrap();
b.iter(|| get_modules(&wmi_con))
});

// baseline: 300ms.
c.bench_function("get_services", |b| {
let wmi_con = WMIConnection::new(COMLibrary::new().unwrap().into()).unwrap();
b.iter(|| get_services(&wmi_con))
});
}

criterion_group!(benches, criterion_benchmark);
Expand Down
2 changes: 1 addition & 1 deletion src/de/wbem_class_de.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ where
let current_field = self
.fields
.next()
.ok_or(format_err!("Expected current field to not be None"))?;
.ok_or_else(|| format_err!("Expected current field to not be None"))?;

let property_value = self
.de
Expand Down

0 comments on commit 79738c3

Please sign in to comment.