Skip to content
This repository has been archived by the owner on Apr 9, 2023. It is now read-only.

Commit

Permalink
Move from nightly bench to bencher crate
Browse files Browse the repository at this point in the history
  • Loading branch information
aahancoc committed Feb 25, 2020
1 parent b992414 commit bdeac42
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 59 deletions.
10 changes: 10 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ scoped_threadpool = { version = "^0.1", optional = true }
walkdir = { version = "^2", optional = true }
num_cpus = { version = "^1", optional = true }

[dev-dependencies]
bencher = "^0.1"

[features]
cli = ["clap", "tabwriter", "scoped_threadpool", "walkdir", "num_cpus"]
default = []
Expand All @@ -34,3 +37,10 @@ path = "src/lib.rs"
required-features = ["cli"]
name = "tmagic"
path = "src/main.rs"

[[bench]]
name = "from_u8"
harness = false
[[bench]]
name = "match_u8"
harness = false
46 changes: 21 additions & 25 deletions benches/from_u8.rs
Original file line number Diff line number Diff line change
@@ -1,29 +1,25 @@
#![feature(test)]
mod from_u8 {
extern crate test;
use self::test::Bencher;
extern crate tree_magic;
#[macro_use]
extern crate bencher;
extern crate tree_magic;
use bencher::Bencher;

///Image tests
#[bench]
fn image_gif(b: &mut Bencher) {
b.iter(|| tree_magic::from_u8(include_bytes!("image/gif")));
}
#[bench]
fn image_png(b: &mut Bencher) {
b.iter(|| tree_magic::from_u8(include_bytes!("image/png")));
}

/// Archive tests
#[bench]
fn application_zip(b: &mut Bencher) {
b.iter(|| tree_magic::from_u8(include_bytes!("application/zip")));
}
///Image tests
fn image_gif(b: &mut Bencher) {
b.iter(|| tree_magic::from_u8(include_bytes!("image/gif")));
}
fn image_png(b: &mut Bencher) {
b.iter(|| tree_magic::from_u8(include_bytes!("image/png")));
}

/// Text tests
#[bench]
fn text_plain(b: &mut Bencher) {
b.iter(|| tree_magic::from_u8(include_bytes!("text/plain")));
}
/// Archive tests
fn application_zip(b: &mut Bencher) {
b.iter(|| tree_magic::from_u8(include_bytes!("application/zip")));
}

/// Text tests
fn text_plain(b: &mut Bencher) {
b.iter(|| tree_magic::from_u8(include_bytes!("text/plain")));
}

benchmark_group!(benches, image_gif, image_png, application_zip, text_plain);
benchmark_main!(benches);
55 changes: 21 additions & 34 deletions benches/match_u8.rs
Original file line number Diff line number Diff line change
@@ -1,38 +1,25 @@
#![feature(test)]
mod match_u8 {
extern crate test;
use self::test::Bencher;
extern crate tree_magic;
#[macro_use]
extern crate bencher;
extern crate tree_magic;
use bencher::Bencher;

#[cfg(not(feature="staticmime"))]
macro_rules! convmime {
($x:expr) => {$x.to_string()}
}
#[cfg(feature="staticmime")]
macro_rules! convmime {
($x:expr) => {$x}
}

///Image benchmarks
#[bench]
fn image_gif(b: &mut Bencher) {
b.iter(|| tree_magic::match_u8("image/gif", include_bytes!("image/gif")));
}
#[bench]
fn image_png(b: &mut Bencher) {
b.iter(|| tree_magic::match_u8("image/png", include_bytes!("image/png")));
}

/// Archive tests
#[bench]
fn application_zip(b: &mut Bencher) {
b.iter(|| tree_magic::match_u8("application/zip", include_bytes!("application/zip")));
}
///Image benchmarks
fn image_gif(b: &mut Bencher) {
b.iter(|| tree_magic::match_u8("image/gif", include_bytes!("image/gif")));
}
fn image_png(b: &mut Bencher) {
b.iter(|| tree_magic::match_u8("image/png", include_bytes!("image/png")));
}

/// Text tests
#[bench]
fn text_plain(b: &mut Bencher) {
b.iter(|| tree_magic::match_u8("text/plain", include_bytes!("text/plain")));
}
/// Archive tests
fn application_zip(b: &mut Bencher) {
b.iter(|| tree_magic::match_u8("application/zip", include_bytes!("application/zip")));
}

/// Text tests
fn text_plain(b: &mut Bencher) {
b.iter(|| tree_magic::match_u8("text/plain", include_bytes!("text/plain")));
}

benchmark_group!(benches, image_gif, image_png, application_zip, text_plain);
benchmark_main!(benches);

0 comments on commit bdeac42

Please sign in to comment.