-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1cda3cd
commit 9ab1187
Showing
4 changed files
with
71 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
[package] | ||
name = "benches" | ||
version = "0.0.0" | ||
edition = "2021" | ||
publish = false | ||
autobenches = false | ||
|
||
[dependencies] | ||
channels = { workspace = true, features = ["full"] } | ||
serde = { version = "1.0", features = ["derive"] } | ||
|
||
[dev-dependencies] | ||
criterion = "0.5.1" | ||
|
||
[[bench]] | ||
name = "send" | ||
path = "send.rs" | ||
harness = false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
use criterion::{ | ||
black_box, criterion_group, criterion_main, Criterion, | ||
}; | ||
|
||
use benches::{complex, simple, Complex, Simple}; | ||
use std::io::empty; | ||
|
||
fn send_simple(c: &mut Criterion) { | ||
let mut sender = channels::Sender::<Simple, _, _>::new(empty()); | ||
|
||
let data = simple(); | ||
|
||
c.bench_function("send simple", |b| { | ||
b.iter(|| sender.send_blocking(black_box(&data)).unwrap()) | ||
}); | ||
} | ||
|
||
fn send_complex(c: &mut Criterion) { | ||
let mut sender = channels::Sender::<Complex, _, _>::new(empty()); | ||
|
||
let data = complex(); | ||
|
||
c.bench_function("send complex", |b| { | ||
b.iter(|| sender.send_blocking(black_box(&data)).unwrap()) | ||
}); | ||
} | ||
|
||
criterion_group!(benches, send_simple, send_complex); | ||
criterion_main!(benches); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
use serde::{Deserialize, Serialize}; | ||
|
||
pub type Simple = i32; | ||
|
||
#[derive(Debug, Serialize, Deserialize)] | ||
pub struct Complex { | ||
pub a: i32, | ||
pub b: usize, | ||
pub c: String, | ||
} | ||
|
||
pub fn simple() -> Simple { | ||
-42 | ||
} | ||
|
||
pub fn complex() -> Complex { | ||
Complex { | ||
a: 42, | ||
b: 0xbadbeef, | ||
c: "This is my beautiful long test string".into(), | ||
} | ||
} |