Skip to content

Instantly share code, notes, and snippets.

@Frando
Last active June 29, 2024 17:11
Show Gist options
  • Save Frando/281f0b23d18d3678dde98ea4a86e6bba to your computer and use it in GitHub Desktop.
Save Frando/281f0b23d18d3678dde98ea4a86e6bba to your computer and use it in GitHub Desktop.
iroh-net local accept&connect loop
use std::time::Instant;
use iroh_net::Endpoint;
const ALPN: &[u8] = b"foo";
#[tokio::main]
async fn main() {
let mut i = 0;
let create_ep = || async move {
Endpoint::builder()
.alpns(vec![ALPN.to_vec()])
.bind(0)
.await
.unwrap()
};
loop {
let bind = Instant::now();
let (ep_alfie, ep_betty) = tokio::join!(create_ep(), create_ep());
let bind = bind.elapsed();
let addr = Instant::now();
let addr_betty = ep_betty.node_addr().await.unwrap();
let addr = addr.elapsed();
let conn = Instant::now();
let (_conn_alfie, _conn_betty) = tokio::join!(
async move { ep_alfie.connect(addr_betty, ALPN).await.unwrap() },
async move { ep_betty.accept().await.unwrap().await.unwrap() }
);
let conn = conn.elapsed();
println!(
"round {: >4}: bind {: >4}ms | addr {: >4}ms | conn {: >4}ms",
i,
bind.as_millis(),
addr.as_millis(),
conn.as_millis()
);
i += 1;
}
}
round 0: bind 3ms | addr 370ms | conn 194ms
round 1: bind 8ms | addr 348ms | conn 8ms
round 2: bind 5ms | addr 342ms | conn 8ms
round 3: bind 7ms | addr 360ms | conn 5ms
round 4: bind 4ms | addr 349ms | conn 8ms
round 5: bind 15ms | addr 356ms | conn 3ms
round 6: bind 5ms | addr 365ms | conn 8ms
round 7: bind 13ms | addr 340ms | conn 8ms
round 8: bind 11ms | addr 346ms | conn 8ms
round 9: bind 6ms | addr 336ms | conn 201ms
round 10: bind 4ms | addr 391ms | conn 8ms
round 11: bind 10ms | addr 351ms | conn 1007ms
round 12: bind 11ms | addr 336ms | conn 8ms
round 13: bind 10ms | addr 356ms | conn 171ms
round 14: bind 8ms | addr 341ms | conn 191ms
round 15: bind 7ms | addr 344ms | conn 1007ms
round 16: bind 7ms | addr 348ms | conn 10ms
round 17: bind 15ms | addr 337ms | conn 8ms
round 18: bind 9ms | addr 342ms | conn 8ms
round 19: bind 7ms | addr 353ms | conn 1004ms
round 20: bind 3ms | addr 327ms | conn 10ms
round 21: bind 10ms | addr 339ms | conn 9ms
round 22: bind 11ms | addr 348ms | conn 1009ms
round 23: bind 9ms | addr 330ms | conn 7ms
round 24: bind 2ms | addr 350ms | conn 8ms
round 25: bind 7ms | addr 340ms | conn 7ms
round 26: bind 11ms | addr 347ms | conn 3ms
round 27: bind 2ms | addr 320ms | conn 165ms
round 28: bind 7ms | addr 350ms | conn 9ms
round 29: bind 16ms | addr 343ms | conn 1008ms
round 30: bind 5ms | addr 356ms | conn 8ms
round 31: bind 8ms | addr 350ms | conn 8ms
round 32: bind 7ms | addr 467ms | conn 8ms
round 33: bind 8ms | addr 357ms | conn 1008ms
round 34: bind 9ms | addr 327ms | conn 8ms
round 35: bind 9ms | addr 345ms | conn 9ms
round 36: bind 9ms | addr 346ms | conn 1006ms
round 37: bind 2ms | addr 363ms | conn 8ms
round 38: bind 7ms | addr 342ms | conn 8ms
round 39: bind 15ms | addr 403ms | conn 8ms
round 40: bind 7ms | addr 346ms | conn 5ms
round 41: bind 4ms | addr 345ms | conn 8ms
round 42: bind 10ms | addr 363ms | conn 3ms
round 43: bind 3ms | addr 334ms | conn 8ms
round 44: bind 12ms | addr 354ms | conn 9ms
round 45: bind 16ms | addr 327ms | conn 8ms
round 46: bind 7ms | addr 327ms | conn 9ms
round 47: bind 10ms | addr 348ms | conn 1008ms
round 48: bind 7ms | addr 360ms | conn 180ms
round 49: bind 7ms | addr 331ms | conn 176ms
round 50: bind 7ms | addr 348ms | conn 8ms
round 51: bind 15ms | addr 397ms | conn 8ms
round 52: bind 9ms | addr 339ms | conn 9ms
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment