diff --git a/Cargo.toml b/Cargo.toml index 66a06ea..1905aaf 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -19,6 +19,7 @@ bitcoin = { git="https://github.com/yancyribbens/rust-bitcoin", rev="254fafdf71b rand = {version = "0.8.5", default-features = false, optional = true} [dev-dependencies] +criterion = "0.3" rust-bitcoin-coin-selection = {path = ".", features = ["rand"]} rand = "0.8.5" diff --git a/README.md b/README.md index 5fc88c4..fbc6013 100644 --- a/README.md +++ b/README.md @@ -19,9 +19,6 @@ As discussed in the literature above, ideally we want to choose a selection from ## Benchmarks -<<<<<<< HEAD -To run the benchmarks use: `RUSTFLAGS='--cfg=bench' cargo +nightly bench`. -======= To run the benchmarks use: `cargo bench`. ### performance comparison @@ -30,9 +27,8 @@ A basic performance comparison between this current [Rust BnB](https://github.co |implementation|pool size|ns/iter| |-------------:|---------|-------| -| Rust BnB| 1,000|823,680| +| Rust BnB| 1,000|695,860| | C++ Core BnB| 1,000|816,374| ->>>>>>> 4ede8d5 (Add cost of change param) ## Minimum Supported Rust Version (MSRV) diff --git a/src/branch_and_bound.rs b/src/branch_and_bound.rs index 088a44e..74ef435 100644 --- a/src/branch_and_bound.rs +++ b/src/branch_and_bound.rs @@ -740,50 +740,3 @@ mod tests { assert!(list.is_none()); } } - -#[cfg(bench)] -#[cfg(test)] -mod benches { - use crate::select_coins_bnb; - use crate::Utxo; - use test::Bencher; - - #[derive(Clone, Debug, Eq, PartialEq)] - struct MinimalUtxo { - value: u64, - } - - impl Utxo for MinimalUtxo { - fn get_value(&self) -> u64 { - self.value - } - } - - #[bench] - /// Creates a UTXO pool of 1,000 coins that do not match and one coin - /// that will be a match when combined with any of the other 1,000 coins. - /// - /// Matching benchmark of Bitcoin core coin-selection benchmark. - // https://github.com/bitcoin/bitcoin/blob/f3bc1a72825fe2b51f4bc20e004cef464f05b965/src/bench/coin_selection.cpp#L44 - fn bench_select_coins_bnb(bh: &mut Bencher) { - // https://github.com/bitcoin/bitcoin/blob/f3bc1a72825fe2b51f4bc20e004cef464f05b965/src/consensus/amount.h#L15 - /// The amount of satoshis in one BTC. - const COIN: u64 = 100_000_000; - - // https://github.com/bitcoin/bitcoin/blob/f3bc1a72825fe2b51f4bc20e004cef464f05b965/src/wallet/coinselection.h#L18 - /// lower bound for randomly-chosen target change amount - const CHANGE_LOWER: u64 = 50_000; - - let u = MinimalUtxo { value: 1000 * COIN }; - let mut utxo_pool = vec![u; 1000]; - utxo_pool.push(MinimalUtxo { value: 3 * COIN }); - - bh.iter(|| { - let result = - select_coins_bnb(1003 * COIN, CHANGE_LOWER, &mut utxo_pool.clone()).unwrap(); - assert_eq!(2, result.len()); - assert_eq!(1000 * COIN, result[0].value); - assert_eq!(3 * COIN, result[1].value); - }); - } -} diff --git a/src/lib.rs b/src/lib.rs index ed2076c..8a67b5a 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -25,7 +25,7 @@ use bitcoin::SignedAmount; use bitcoin::TxOut; use bitcoin::Weight; -use crate::branch_and_bound::select_coins_bnb; +pub use crate::branch_and_bound::select_coins_bnb; use crate::single_random_draw::select_coins_srd; use bitcoin::blockdata::transaction::TxIn; use rand::thread_rng;