Skip to content

Commit 45a889b

Browse files
performance sample cleaned up (#58)
1 parent d288280 commit 45a889b

File tree

2 files changed

+23
-25
lines changed
  • rustecal-samples/benchmarks

2 files changed

+23
-25
lines changed

rustecal-samples/benchmarks/performance_receive/src/main.rs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ use rustecal_types_bytes::BytesMessage;
88

99
fn main() -> Result<(), Box<dyn std::error::Error>> {
1010
// initialize eCAL
11-
Ecal::initialize(Some("performance receive rust"), EcalComponents::DEFAULT, None)?;
11+
Ecal::initialize(Some("performance receive rust"), EcalComponents::DEFAULT, None)
12+
.expect("eCAL initialization failed");
1213

1314
// create a typed subscriber for raw bytes
1415
let mut subscriber: TypedSubscriber<BytesMessage> = TypedSubscriber::new("Performance")?;
@@ -18,7 +19,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
1819
let bytes = Arc::new(std::sync::atomic::AtomicU64::new(0));
1920
let start = Arc::new(Mutex::new(Instant::now()));
2021

21-
// register the receivecallback
22+
// register the receive-callback
2223
{
2324
let msgs = Arc::clone(&msgs);
2425
let bytes = Arc::clone(&bytes);
@@ -49,12 +50,12 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
4950
let msg_s = (m as f64) / secs;
5051
let latency_us = (secs * 1e6) / (m as f64);
5152

52-
println!("Payload size : {} kB", buffer.len() / 1024);
53-
println!("Throughput (kB/s) : {:.0}", kbyte_s);
54-
println!("Throughput (MB/s) : {:.2}", mbyte_s);
55-
println!("Throughput (GB/s) : {:.3}", gbyte_s);
56-
println!("Messages/s : {:.0}", msg_s);
57-
println!("Latency (µs) : {:.2}", latency_us);
53+
println!("Payload size (kB) : {:.0}", buffer.len() / 1024);
54+
println!("Throughput (kB/s) : {:.0}", kbyte_s);
55+
println!("Throughput (MB/s) : {:.2}", mbyte_s);
56+
println!("Throughput (GB/s) : {:.2}", gbyte_s);
57+
println!("Messages (1/s) : {:.0}", msg_s);
58+
println!("Latency (µs) : {:.2}", latency_us);
5859
println!();
5960

6061
// reset the timer

rustecal-samples/benchmarks/performance_send/src/main.rs

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
2626
}
2727

2828
// log performance settings
29-
println!("Zero copy mode: {}", ZERO_COPY);
30-
println!("Number of write buffers: {}", BUFFER_COUNT);
31-
println!("Acknowledge timeout: {} ms", ACKNOWLEDGE_TIMEOUT_MS);
32-
println!("Payload size: {} bytes", payload_size);
29+
println!("Zero copy mode : {}", ZERO_COPY);
30+
println!("Number of write buffers : {}", BUFFER_COUNT);
31+
println!("Acknowledge timeout : {} ms", ACKNOWLEDGE_TIMEOUT_MS);
32+
println!("Payload size : {} bytes", payload_size);
3333
println!();
3434

3535
// prepare and tweak eCAL Configuration
@@ -39,12 +39,8 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
3939
cfg.publisher.layer.shm.acknowledge_timeout_ms = ACKNOWLEDGE_TIMEOUT_MS as u32;
4040

4141
// initialize eCAL with custom config
42-
Ecal::initialize(
43-
Some("performance send rust"),
44-
EcalComponents::DEFAULT,
45-
Some(&cfg),
46-
)
47-
.expect("eCAL initialization failed");
42+
Ecal::initialize(Some("performance send rust"), EcalComponents::DEFAULT, Some(&cfg))
43+
.expect("eCAL initialization failed");
4844

4945
// create payload buffer and publisher
5046
let payload_vec: Vec<u8> = vec![0u8; payload_size];
@@ -62,6 +58,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
6258
println!("Waiting for performance receive to start ...");
6359
std::thread::sleep(Duration::from_millis(1000));
6460
}
61+
println!();
6562

6663
// send loop
6764
while Ecal::ok() {
@@ -75,7 +72,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
7572
let wrapped = BytesMessage { data: payload.clone() };
7673
publisher.send(&wrapped);
7774

78-
msgs_sent += 1;
75+
msgs_sent += 1;
7976
bytes_sent += payload_size as u64;
8077
iterations += 1;
8178

@@ -90,12 +87,12 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
9087
let msg_s = (msgs_sent as f64) / secs;
9188
let latency_us = (secs * 1e6) / (msgs_sent as f64);
9289

93-
println!("Payload size : {} kB", payload_size / 1024);
94-
println!("Throughput (kB/s) : {:.0}", kbyte_s);
95-
println!("Throughput (MB/s) : {:.2}", mbyte_s);
96-
println!("Throughput (GB/s) : {:.3}", gbyte_s);
97-
println!("Messages/s : {:.0}", msg_s);
98-
println!("Latency (µs) : {:.2}", latency_us);
90+
println!("Payload size (kB) : {:.0}", payload_size / 1024);
91+
println!("Throughput (kB/s) : {:.0}", kbyte_s);
92+
println!("Throughput (MB/s) : {:.2}", mbyte_s);
93+
println!("Throughput (GB/s) : {:.2}", gbyte_s);
94+
println!("Messages (1/s) : {:.0}", msg_s);
95+
println!("Latency (µs) : {:.2}", latency_us);
9996
println!();
10097

10198
msgs_sent = 0;

0 commit comments

Comments
 (0)