Skip to content

Commit

Permalink
Reverting back all commented benchmarks
Browse files Browse the repository at this point in the history
  • Loading branch information
svartalf committed May 23, 2020
1 parent 60997c3 commit bb93298
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 63 deletions.
1 change: 0 additions & 1 deletion benchmarks/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ publish = false
[dependencies]
heim = { path = "../heim", features = ["full"] }
futures = "~0.3"
tokio = { version = "~0.2", features = ["rt-threaded"] }
criterion = "~0.3"
smol = "~0.1"

Expand Down
6 changes: 3 additions & 3 deletions benchmarks/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ criterion::criterion_main!(
benchmarks::disk::bench,
benchmarks::host::bench,
benchmarks::memory::bench,
// benchmarks::net::bench,
// benchmarks::process::bench,
// benchmarks::virt::bench,
benchmarks::net::bench,
benchmarks::process::bench,
benchmarks::virt::bench,
);
6 changes: 3 additions & 3 deletions benchmarks/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ pub mod cpu;
pub mod disk;
pub mod host;
pub mod memory;
//pub mod net;
//pub mod process;
//pub mod virt;
pub mod net;
pub mod process;
pub mod virt;
6 changes: 0 additions & 6 deletions benchmarks/src/memory.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
use criterion::{criterion_group, Criterion};

pub fn inner(c: &mut Criterion) {
// let mut rt = tokio::runtime::Builder::new()
// .threaded_scheduler()
// .enable_all()
// .build()
// .unwrap();

c.bench_function("memory_memory", |b| {
b.iter(|| smol::block_on(heim::memory::memory()))
});
Expand Down
20 changes: 10 additions & 10 deletions benchmarks/src/net.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,23 @@ use criterion::{criterion_group, Criterion};
use futures::prelude::*;

pub fn inner(c: &mut Criterion) {
let mut rt = tokio::runtime::Builder::new()
.threaded_scheduler()
.enable_all()
.build()
.unwrap();

c.bench_function("net_io_counters", |b| {
b.iter(|| {
let stream = heim::net::io_counters().for_each(|_| async {});
rt.block_on(stream)
smol::block_on(async {
heim::net::io_counters().await?.for_each(|_| async {}).await;

Ok::<(), heim::Error>(())
})
})
});

c.bench_function("net_nic", |b| {
b.iter(|| {
let stream = heim::net::nic().for_each(|_| async {});
rt.block_on(stream)
smol::block_on(async {
heim::net::nic().for_each(|_| async {}).await;

Ok::<(), heim::Error>(())
})
})
});
}
Expand Down
73 changes: 40 additions & 33 deletions benchmarks/src/process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,26 @@ use criterion::{criterion_group, Criterion};
use futures::prelude::*;

pub fn inner(c: &mut Criterion) {
let mut rt = tokio::runtime::Builder::new()
.threaded_scheduler()
.enable_all()
.build()
.unwrap();

c.bench_function("process_pids", |b| {
b.iter(|| {
let stream = heim::process::pids().for_each(|_| async {});
rt.block_on(stream)
smol::block_on(async {
heim::process::pids().await?.for_each(|_| async {}).await;

Ok::<(), heim::Error>(())
})
})
});

c.bench_function("process_processes", |b| {
b.iter(|| {
let stream = heim::process::processes().for_each(|_| async {});
rt.block_on(stream)
smol::block_on(async {
heim::process::processes()
.await?
.for_each(|_| async {})
.await;

Ok::<(), heim::Error>(())
})
})
});

Expand All @@ -29,29 +32,33 @@ pub fn inner(c: &mut Criterion) {
// as the both stream and inner futures must be executed for as much as possible
c.bench_function("process_processes_full", |b| {
b.iter(|| {
let stream =
heim::process::processes().for_each_concurrent(None, |process| async move {
let process = match process {
Ok(p) => p,
Err(..) => return,
};

let _ = tokio::join!(
process.parent_pid(),
process.name(),
process.exe(),
process.command(),
process.cwd(),
process.status(),
process.create_time(),
process.cpu_time(),
process.cpu_usage(),
process.memory(),
process.is_running(),
);
});

rt.block_on(stream)
smol::block_on(async {
heim::process::processes()
.await?
.for_each_concurrent(None, |process| async move {
let process = match process {
Ok(p) => p,
Err(..) => return,
};

let _ = futures::join!(
process.parent_pid(),
process.name(),
process.exe(),
process.command(),
process.cwd(),
process.status(),
process.create_time(),
process.cpu_time(),
process.cpu_usage(),
process.memory(),
process.is_running(),
);
})
.await;

Ok::<(), heim::Error>(())
})
})
});
}
Expand Down
8 changes: 1 addition & 7 deletions benchmarks/src/virt.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,8 @@
use criterion::{criterion_group, Criterion};

pub fn inner(c: &mut Criterion) {
let mut rt = tokio::runtime::Builder::new()
.threaded_scheduler()
.enable_all()
.build()
.unwrap();

c.bench_function("virt_detect", |b| {
b.iter(|| rt.block_on(heim::virt::detect()))
b.iter(|| smol::block_on(heim::virt::detect()))
});
}

Expand Down

0 comments on commit bb93298

Please sign in to comment.