Skip to content

Commit

Permalink
Sample size in zn_thr_pub can be configured
Browse files Browse the repository at this point in the history
  • Loading branch information
Mallets committed Sep 8, 2020
1 parent e11ae20 commit 0bd1634
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions zenoh/examples/zenoh-net/zn_sub_thr.rs
Expand Up @@ -17,14 +17,12 @@ use std::time::Instant;
use zenoh::net::ResKey::*;
use zenoh::net::*;

const N: u128 = 100000;

#[async_std::main]
async fn main() {
// initiate logging
env_logger::init();

let (config, m) = parse_args();
let (config, m, n) = parse_args();

let session = open(config, None).await.unwrap();

Expand All @@ -47,10 +45,10 @@ async fn main() {
if count == 0 {
start = Instant::now();
count += 1;
} else if count < N {
} else if count < n {
count += 1;
} else {
print_stats(start);
print_stats(start, n);
nm += 1;
count = 0;
if nm >= m {
Expand All @@ -69,13 +67,13 @@ async fn main() {
// session.close().await.unwrap();
}

fn print_stats(start: Instant) {
fn print_stats(start: Instant, n: u128) {
let elapsed = start.elapsed().as_secs_f64();
let thpt = (N as f64) / elapsed;
let thpt = (n as f64) / elapsed;
println!("{} msg/s", thpt);
}

fn parse_args() -> (Config, u32) {
fn parse_args() -> (Config, u32, u128) {
let args = App::new("zenoh-net throughput sub example")
.arg(
Arg::from_usage("-m, --mode=[MODE] 'The zenoh session mode.")
Expand All @@ -92,9 +90,16 @@ fn parse_args() -> (Config, u32) {
Arg::from_usage("-s, --samples=[number] 'Number of throughput measurements.'")
.default_value("10"),
)
.arg(
Arg::from_usage(
"-n, --number=[number] 'Number of messages in each throughput measurements.'",
)
.default_value("100000"),
)
.get_matches();

let s: u32 = args.value_of("samples").unwrap().parse().unwrap();
let n: u128 = args.value_of("number").unwrap().parse().unwrap();
let c = Config::default()
.mode(
args.value_of("mode")
Expand All @@ -114,5 +119,5 @@ fn parse_args() -> (Config, u32) {
.or_else(|| Some(vec![]))
.unwrap(),
);
(c, s)
(c, s, n)
}

0 comments on commit 0bd1634

Please sign in to comment.