Skip to content

Commit f781715

Browse files
committed
nostr: add benches for parsing relay URLs
Signed-off-by: Yuki Kishimoto <[email protected]>
1 parent 6dc4555 commit f781715

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

crates/nostr/src/types/url.rs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -491,3 +491,34 @@ mod tests {
491491
assert_eq!(url.domain(), None);
492492
}
493493
}
494+
495+
#[cfg(bench)]
496+
mod benches {
497+
use super::*;
498+
use crate::test::{black_box, Bencher};
499+
500+
const LOCAL_URL: &str = "ws://127.0.0.1:7777";
501+
const CLEARNET_URL: &str = "wss://relay.damus.io";
502+
const ONION_URL: &str = "ws://oxtrdevav64z64yb7x6rjg4ntzqjhedm5b5zjqulugknhzr46ny2qbad.onion";
503+
504+
#[bench]
505+
pub fn parse_local_relay_url(bh: &mut Bencher) {
506+
bh.iter(|| {
507+
black_box(RelayUrl::parse(LOCAL_URL)).unwrap();
508+
});
509+
}
510+
511+
#[bench]
512+
pub fn parse_clearnet_relay_url(bh: &mut Bencher) {
513+
bh.iter(|| {
514+
black_box(RelayUrl::parse(CLEARNET_URL)).unwrap();
515+
});
516+
}
517+
518+
#[bench]
519+
pub fn parse_onion_relay_url(bh: &mut Bencher) {
520+
bh.iter(|| {
521+
black_box(RelayUrl::parse(ONION_URL)).unwrap();
522+
});
523+
}
524+
}

0 commit comments

Comments
 (0)