Skip to content

Commit 08b4216

Browse files
committed
nostr: update NostrParser benches
Signed-off-by: Yuki Kishimoto <yukikishimoto@protonmail.com>
1 parent 1f6a53f commit 08b4216

File tree

1 file changed

+27
-2
lines changed

1 file changed

+27
-2
lines changed

crates/nostr/src/parser.rs

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -450,10 +450,35 @@ mod benches {
450450
use super::*;
451451

452452
#[bench]
453-
pub fn bench_parse_text(bh: &mut Bencher) {
453+
pub fn bench_parse_text_with_nostr_uris(bh: &mut Bencher) {
454454
let text: &str = "I have never been very active in discussions but working on rust-nostr (at the time called nostr-rs-sdk) since September 2022 🦀 \n\nIf I remember correctly there were also nostr:nprofile1qqsqfyvdlsmvj0nakmxq6c8n0c2j9uwrddjd8a95ynzn9479jhlth3gpvemhxue69uhkv6tvw3jhytnwdaehgu3wwa5kuef0dec82c33w94xwcmdd3cxketedsux6ertwecrgues0pk8xdrew33h27pkd4unvvpkw3nkv7pe0p68gat58ycrw6ps0fenwdnvva48w0mzwfhkzerrv9ehg0t5wf6k2qgnwaehxw309ac82unsd3jhqct89ejhxtcpz4mhxue69uhhyetvv9ujuerpd46hxtnfduhsh8njvk and nostr:nprofile1qqswuyd9ml6qcxd92h6pleptfrcqucvvjy39vg4wx7mv9wm8kakyujgpypmhxue69uhkx6r0wf6hxtndd94k2erfd3nk2u3wvdhk6w35xs6z7qgwwaehxw309ahx7uewd3hkctcpypmhxue69uhkummnw3ezuetfde6kuer6wasku7nfvuh8xurpvdjj7a0nq40";
455+
456+
let parser = NostrParser::new();
457+
458+
bh.iter(|| {
459+
black_box(parser.parse(text).collect::<Vec<_>>());
460+
});
461+
}
462+
463+
#[bench]
464+
pub fn bench_parse_text_with_urls(bh: &mut Bencher) {
465+
let text: &str = "I've uses both the book and rustlings: https://github.com/rust-lang/rustlings/\n\nThere is also the \"Rust by example\" book: https://doc.rust-lang.org/rust-by-example/\n\nWhile you read the book, try to make projects from scratch (not just simple ones). At the end, writing code is the best way to learn it.";
466+
467+
let parser = NostrParser::new();
468+
469+
bh.iter(|| {
470+
black_box(parser.parse(text).collect::<Vec<_>>());
471+
});
472+
}
473+
474+
#[bench]
475+
pub fn bench_parse_text_with_hashtags(bh: &mut Bencher) {
476+
let text: &str = "Hey #rust-nostr fans, can you enlighten me please:\nWhen I am calculating my Web of Trust I do the following:\n0. Create client with outbox model enabled\n1. Get my follows, mutes, reports in one fetch call\n2. Get follows, mutes, reports of my follows in another fetch call, using an authors filter that has all follows in it\n3. Calculate scores with my weights locally\n\nQuestion:\nWhy did step 2. take hours to complete?\n\nIt seems like it's trying to connect to loads of relays.\nMy guess is either I am doing sth horribly wrong or there is no smart relay set calculation for filters in the pool.\n\nIn ndk this calculation takes under 10 seconds to complete, even without any caching. It will first look at the filters and calculate a relay set that has all authors in it then does the fetching.\n\n#asknostr #rust";
477+
478+
let parser = NostrParser::new();
479+
455480
bh.iter(|| {
456-
black_box(parse_text(text)).unwrap();
481+
black_box(parser.parse(text).collect::<Vec<_>>());
457482
});
458483
}
459484
}

0 commit comments

Comments
 (0)