Skip to content

Commit

Permalink
Add benchmarks testing the constructors
Browse files Browse the repository at this point in the history
  • Loading branch information
tbu- authored and soc committed Apr 16, 2018
1 parent 92a1945 commit 62ba8f3
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
7 changes: 7 additions & 0 deletions Cargo.toml
Expand Up @@ -11,3 +11,10 @@ keywords = ["xdg", "basedir", "app_dirs", "path", "folder"]

[dependencies]
winapi = { version = "0.3", features = ["knownfolders", "objbase", "shlobj"] }

[dev-dependencies]
bencher = "0.1.5"

[[bench]]
name = "constructors"
harness = false
41 changes: 41 additions & 0 deletions benches/constructors.rs
@@ -0,0 +1,41 @@
#[macro_use]
extern crate bencher;
extern crate directories;

use bencher::Bencher;
use bencher::black_box;
use directories::BaseDirs;
use directories::ProjectDirs;
use directories::UserDirs;

fn base_dirs(b: &mut Bencher) {
b.iter(|| {
let _ = black_box(BaseDirs::new());
});
}

fn user_dirs(b: &mut Bencher) {
b.iter(|| {
let _ = black_box(UserDirs::new());
});
}

fn project_dirs_from_path(b: &mut Bencher) {
b.iter(|| {
let _ = black_box(ProjectDirs::from_path(Default::default()));
});
}

fn project_dirs(b: &mut Bencher) {
b.iter(|| {
let _ = black_box(ProjectDirs::from("org", "foo", "Bar App"));
});
}

benchmark_group!(constructors,
base_dirs,
user_dirs,
project_dirs_from_path,
project_dirs,
);
benchmark_main!(constructors);

0 comments on commit 62ba8f3

Please sign in to comment.