|
64 | 64 |
|
65 | 65 | #![cfg_attr(all(not(feature = "std"), not(test)), no_std)] |
66 | 66 |
|
67 | | -// Allow and import test features for benching |
68 | | -#![cfg_attr(all(test, feature = "_bench_unstable"), feature(test))] |
69 | | -#[cfg(all(test, feature = "_bench_unstable"))] |
70 | | -extern crate test; |
| 67 | +#[cfg(ldk_bench)] extern crate criterion; |
71 | 68 |
|
72 | 69 | #[cfg(not(feature = "std"))] |
73 | 70 | extern crate alloc; |
@@ -287,36 +284,42 @@ mod tests { |
287 | 284 | } |
288 | 285 | } |
289 | 286 |
|
290 | | -#[cfg(all(test, feature = "_bench_unstable"))] |
| 287 | +#[cfg(ldk_bench)] |
| 288 | +/// Benches |
291 | 289 | pub mod bench { |
292 | | - use test::Bencher; |
293 | | - |
294 | 290 | use bitcoin::Network; |
295 | 291 |
|
296 | | - use lightning::ln::msgs::DecodeError; |
| 292 | + use criterion::Criterion; |
| 293 | + |
| 294 | + use std::fs; |
| 295 | + |
297 | 296 | use lightning::routing::gossip::NetworkGraph; |
298 | 297 | use lightning::util::test_utils::TestLogger; |
299 | 298 |
|
300 | 299 | use crate::RapidGossipSync; |
301 | 300 |
|
302 | | - #[bench] |
303 | | - fn bench_reading_full_graph_from_file(b: &mut Bencher) { |
| 301 | + /// Bench! |
| 302 | + pub fn bench_reading_full_graph_from_file(b: &mut Criterion) { |
304 | 303 | let logger = TestLogger::new(); |
305 | | - b.iter(|| { |
| 304 | + b.bench_function("read_full_graph_from_rgs", |b| b.iter(|| { |
306 | 305 | let network_graph = NetworkGraph::new(Network::Bitcoin, &logger); |
307 | 306 | let rapid_sync = RapidGossipSync::new(&network_graph, &logger); |
308 | | - let sync_result = rapid_sync.sync_network_graph_with_file_path("./res/full_graph.lngossip"); |
309 | | - if let Err(crate::error::GraphSyncError::DecodeError(DecodeError::Io(io_error))) = &sync_result { |
310 | | - let error_string = format!("Input file lightning-rapid-gossip-sync/res/full_graph.lngossip is missing! Download it from https://bitcoin.ninja/ldk-compressed_graph-bc08df7542-2022-05-05.bin\n\n{:?}", io_error); |
311 | | - #[cfg(not(require_route_graph_test))] |
312 | | - { |
313 | | - println!("{}", error_string); |
314 | | - return; |
315 | | - } |
316 | | - #[cfg(require_route_graph_test)] |
317 | | - panic!("{}", error_string); |
318 | | - } |
319 | | - assert!(sync_result.is_ok()) |
320 | | - }); |
| 307 | + let mut file = match fs::read("../lightning-rapid-gossip-sync/res/full_graph.lngossip") { |
| 308 | + Ok(f) => f, |
| 309 | + Err(io_error) => { |
| 310 | + let error_string = format!( |
| 311 | + "Input file lightning-rapid-gossip-sync/res/full_graph.lngossip is missing! Download it from https://bitcoin.ninja/ldk-compressed_graph-bc08df7542-2022-05-05.bin\n\n{:?}", |
| 312 | + io_error); |
| 313 | + #[cfg(not(require_route_graph_test))] |
| 314 | + { |
| 315 | + println!("{}", error_string); |
| 316 | + return; |
| 317 | + } |
| 318 | + #[cfg(require_route_graph_test)] |
| 319 | + panic!("{}", error_string); |
| 320 | + }, |
| 321 | + }; |
| 322 | + rapid_sync.update_network_graph_no_std(&mut file, None).unwrap(); |
| 323 | + })); |
321 | 324 | } |
322 | 325 | } |
0 commit comments