Skip to content

Commit 77fd712

Browse files
committed
Add a trivial benchmark of calculating routes on today's graph
Sadly rust upstream never really figured out the benchmark story, and it looks like the API we use here may not be long for this world. Luckily, we can switch to criterion with largely the same API if that happens before upstream finishes ongoing work with the custom test framework stuff. Sadly, it requires fetching the current network graph, which I did using Val's route-testing script written to test the MPP router.
1 parent b6d806c commit 77fd712

File tree

3 files changed

+33
-0
lines changed

3 files changed

+33
-0
lines changed

lightning/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ max_level_debug = []
2323
# Allow signing of local transactions that may have been revoked or will be revoked, for functional testing (e.g. justice tx handling).
2424
# This is unsafe to use in production because it may result in the counterparty publishing taking our funds.
2525
unsafe_revoked_tx_signing = []
26+
unstable = []
2627

2728
[dependencies]
2829
bitcoin = "0.24"

lightning/src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@
2727
#![allow(bare_trait_objects)]
2828
#![allow(ellipsis_inclusive_range_patterns)]
2929

30+
#![cfg_attr(all(test, feature = "unstable"), feature(test))]
31+
#[cfg(all(test, feature = "unstable"))] extern crate test;
32+
3033
extern crate bitcoin;
3134
#[cfg(any(test, feature = "_test_utils"))] extern crate hex;
3235
#[cfg(any(test, feature = "fuzztarget", feature = "_test_utils"))] extern crate regex;

lightning/src/routing/router.rs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1279,3 +1279,32 @@ mod tests {
12791279
assert_eq!(route.paths[0][1].channel_features.le_flags(), &[0; 0]); // We can't learn any flags from invoices, sadly
12801280
}
12811281
}
1282+
1283+
#[cfg(all(test, feature = "unstable"))]
1284+
mod benches {
1285+
use super::*;
1286+
use util::logger::{Logger, Record};
1287+
1288+
use std::fs::File;
1289+
use test::Bencher;
1290+
1291+
struct DummyLogger {}
1292+
impl Logger for DummyLogger {
1293+
fn log(&self, _record: &Record) {}
1294+
}
1295+
1296+
#[bench]
1297+
fn generate_routes(bench: &mut Bencher) {
1298+
let mut seed: usize = 0xdeadbeef;
1299+
let mut d = File::open("net_graph-2021-02-12.bin").expect("Please fetch https://bitcoin.ninja/ldk-net_graph-879e309c128-2020-02-12.bin and place it at lightning/net_graph-2021-02-12.bin");
1300+
let graph = NetworkGraph::read(&mut d).unwrap();
1301+
let node_count = graph.get_nodes().len();
1302+
bench.iter(|| {
1303+
seed *= 0xdeadbeef;
1304+
let src = graph.get_nodes().keys().skip(seed % node_count).next().unwrap();
1305+
seed *= 0xdeadbeef;
1306+
let dst = graph.get_nodes().keys().skip(seed % node_count).next().unwrap();
1307+
let _ = get_route(src, &graph, dst, None, &[], seed as u64 % 1_000_000, 42, &DummyLogger{});
1308+
});
1309+
}
1310+
}

0 commit comments

Comments
 (0)