-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
1,104 additions
and
0 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
use criterion::{black_box, criterion_group, criterion_main, Criterion}; | ||
use rust_coinselect::{ | ||
select_coin, CoinSelectionOpt, ExcessStrategy, OutputGroup, SelectionError, SelectionOutput, | ||
}; | ||
|
||
fn benchmark_select_coin(c: &mut Criterion) { | ||
let inputs = [ | ||
OutputGroup { | ||
value: 55000, | ||
weight: 500, | ||
input_count: 1, | ||
is_segwit: false, | ||
creation_sequence: None, | ||
}, | ||
OutputGroup { | ||
value: 400, | ||
weight: 200, | ||
input_count: 1, | ||
is_segwit: false, | ||
creation_sequence: None, | ||
}, | ||
OutputGroup { | ||
value: 40000, | ||
weight: 300, | ||
input_count: 1, | ||
is_segwit: false, | ||
creation_sequence: None, | ||
}, | ||
OutputGroup { | ||
value: 25000, | ||
weight: 100, | ||
input_count: 1, | ||
is_segwit: false, | ||
creation_sequence: None, | ||
}, | ||
OutputGroup { | ||
value: 35000, | ||
weight: 150, | ||
input_count: 1, | ||
is_segwit: false, | ||
creation_sequence: None, | ||
}, | ||
OutputGroup { | ||
value: 600, | ||
weight: 250, | ||
input_count: 1, | ||
is_segwit: false, | ||
creation_sequence: None, | ||
}, | ||
OutputGroup { | ||
value: 30000, | ||
weight: 120, | ||
input_count: 1, | ||
is_segwit: false, | ||
creation_sequence: None, | ||
}, | ||
OutputGroup { | ||
value: 5000, | ||
weight: 50, | ||
input_count: 1, | ||
is_segwit: false, | ||
creation_sequence: None, | ||
}, | ||
]; | ||
|
||
let options = CoinSelectionOpt { | ||
target_value: 5730, | ||
target_feerate: 0.5, // Simplified feerate | ||
long_term_feerate: None, | ||
min_absolute_fee: 0, | ||
base_weight: 10, | ||
drain_weight: 50, | ||
drain_cost: 10, | ||
cost_per_input: 20, | ||
cost_per_output: 10, | ||
min_drain_value: 500, | ||
excess_strategy: ExcessStrategy::ToDrain, | ||
}; | ||
|
||
c.bench_function("select_coin", |b| { | ||
b.iter(|| { | ||
let result: Result<SelectionOutput, SelectionError> = | ||
select_coin(black_box(&inputs), black_box(options)); | ||
let _ = black_box(result); | ||
}) | ||
}); | ||
} | ||
|
||
criterion_group!(benches, benchmark_select_coin); | ||
criterion_main!(benches); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
use criterion::{black_box, criterion_group, criterion_main, Criterion}; | ||
use rust_coinselect::{ | ||
select_coin_bnb, CoinSelectionOpt, ExcessStrategy, OutputGroup, SelectionError, SelectionOutput, | ||
}; | ||
|
||
fn benchmark_select_coin_bnb(c: &mut Criterion) { | ||
let inputs = [ | ||
OutputGroup { | ||
value: 55000, | ||
weight: 500, | ||
input_count: 1, | ||
is_segwit: false, | ||
creation_sequence: None, | ||
}, | ||
OutputGroup { | ||
value: 400, | ||
weight: 200, | ||
input_count: 1, | ||
is_segwit: false, | ||
creation_sequence: None, | ||
}, | ||
OutputGroup { | ||
value: 40000, | ||
weight: 300, | ||
input_count: 1, | ||
is_segwit: false, | ||
creation_sequence: None, | ||
}, | ||
OutputGroup { | ||
value: 25000, | ||
weight: 100, | ||
input_count: 1, | ||
is_segwit: false, | ||
creation_sequence: None, | ||
}, | ||
OutputGroup { | ||
value: 35000, | ||
weight: 150, | ||
input_count: 1, | ||
is_segwit: false, | ||
creation_sequence: None, | ||
}, | ||
OutputGroup { | ||
value: 600, | ||
weight: 250, | ||
input_count: 1, | ||
is_segwit: false, | ||
creation_sequence: None, | ||
}, | ||
OutputGroup { | ||
value: 30000, | ||
weight: 120, | ||
input_count: 1, | ||
is_segwit: false, | ||
creation_sequence: None, | ||
}, | ||
OutputGroup { | ||
value: 5000, | ||
weight: 50, | ||
input_count: 1, | ||
is_segwit: false, | ||
creation_sequence: None, | ||
}, | ||
]; | ||
|
||
let options = CoinSelectionOpt { | ||
target_value: 5730, | ||
target_feerate: 0.5, // Simplified feerate | ||
long_term_feerate: None, | ||
min_absolute_fee: 0, | ||
base_weight: 10, | ||
drain_weight: 50, | ||
drain_cost: 10, | ||
cost_per_input: 20, | ||
cost_per_output: 10, | ||
min_drain_value: 500, | ||
excess_strategy: ExcessStrategy::ToDrain, | ||
}; | ||
|
||
c.bench_function("select_coin_bnb", |b| { | ||
b.iter(|| { | ||
let result: Result<SelectionOutput, SelectionError> = | ||
select_coin_bnb(black_box(&inputs), black_box(options)); | ||
let _ = black_box(result); | ||
}) | ||
}); | ||
} | ||
|
||
criterion_group!(benches, benchmark_select_coin_bnb); | ||
criterion_main!(benches); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
use criterion::{black_box, criterion_group, criterion_main, Criterion}; | ||
use rust_coinselect::{ | ||
select_coin_fifo, CoinSelectionOpt, ExcessStrategy, OutputGroup, SelectionError, | ||
SelectionOutput, | ||
}; | ||
|
||
fn benchmark_select_coin_fifo(c: &mut Criterion) { | ||
let inputs = vec![ | ||
OutputGroup { | ||
value: 1000, | ||
weight: 100, | ||
input_count: 1, | ||
is_segwit: false, | ||
creation_sequence: None, | ||
}, | ||
OutputGroup { | ||
value: 2000, | ||
weight: 200, | ||
input_count: 1, | ||
is_segwit: false, | ||
creation_sequence: None, | ||
}, | ||
OutputGroup { | ||
value: 3000, | ||
weight: 300, | ||
input_count: 1, | ||
is_segwit: false, | ||
creation_sequence: None, | ||
}, | ||
]; | ||
|
||
let options = CoinSelectionOpt { | ||
target_value: 2500, | ||
target_feerate: 0.4, | ||
long_term_feerate: Some(0.4), | ||
min_absolute_fee: 0, | ||
base_weight: 10, | ||
drain_weight: 50, | ||
drain_cost: 10, | ||
cost_per_input: 20, | ||
cost_per_output: 10, | ||
min_drain_value: 500, | ||
excess_strategy: ExcessStrategy::ToDrain, | ||
}; | ||
|
||
c.bench_function("select_coin_fifo", |b| { | ||
b.iter(|| { | ||
let result: Result<SelectionOutput, SelectionError> = | ||
select_coin_fifo(black_box(&inputs), black_box(options)); | ||
let _ = black_box(result); | ||
}) | ||
}); | ||
} | ||
|
||
criterion_group!(benches, benchmark_select_coin_fifo); | ||
criterion_main!(benches); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
use criterion::{black_box, criterion_group, criterion_main, Criterion}; | ||
use rust_coinselect::{ | ||
select_coin_knapsack, CoinSelectionOpt, ExcessStrategy, OutputGroup, SelectionError, | ||
SelectionOutput, | ||
}; | ||
|
||
const CENT: f64 = 1000000.0; | ||
|
||
fn knapsack_setup_output_groups( | ||
value: Vec<u64>, | ||
weights: Vec<u32>, | ||
target_feerate: f32, | ||
) -> Vec<OutputGroup> { | ||
let mut inputs: Vec<OutputGroup> = Vec::new(); | ||
for (i, j) in value.into_iter().zip(weights.into_iter()) { | ||
let k = i.saturating_add((j as f32 * target_feerate).ceil() as u64); | ||
inputs.push(OutputGroup { | ||
value: k, | ||
weight: j, | ||
input_count: 1, | ||
is_segwit: false, | ||
creation_sequence: None, | ||
}) | ||
} | ||
inputs | ||
} | ||
|
||
fn benchmark_select_coin_knapsack(c: &mut Criterion) { | ||
let inputs = knapsack_setup_output_groups( | ||
vec![ | ||
(6.0 * CENT).round() as u64, | ||
(7.0 * CENT).round() as u64, | ||
(8.0 * CENT).round() as u64, | ||
(20.0 * CENT).round() as u64, | ||
(30.0 * CENT).round() as u64, | ||
], | ||
vec![100, 200, 100, 10, 5], | ||
0.77, | ||
); | ||
|
||
let options = { | ||
let min_drain_value = 500; | ||
let base_weight = 10; | ||
let target_feerate = 0.56; | ||
let adjusted_target = (37.0 * CENT).round() as u64; | ||
let target_value = | ||
adjusted_target - min_drain_value - (base_weight as f32 * target_feerate).ceil() as u64; | ||
CoinSelectionOpt { | ||
target_value, | ||
target_feerate, | ||
long_term_feerate: Some(0.4), | ||
min_absolute_fee: 0, | ||
base_weight, | ||
drain_weight: 50, | ||
drain_cost: 10, | ||
cost_per_input: 20, | ||
cost_per_output: 10, | ||
min_drain_value, | ||
excess_strategy: ExcessStrategy::ToDrain, | ||
} | ||
}; | ||
|
||
c.bench_function("select_coin_knapsack", |b| { | ||
b.iter(|| { | ||
let result: Result<SelectionOutput, SelectionError> = | ||
select_coin_knapsack(black_box(&inputs), black_box(options)); | ||
let _ = black_box(result); | ||
}) | ||
}); | ||
} | ||
|
||
criterion_group!(benches, benchmark_select_coin_knapsack); | ||
criterion_main!(benches); |
Oops, something went wrong.