Skip to content

Commit

Permalink
Merge pull request #3075 from stacks-network/feat/c32-optimizations
Browse files Browse the repository at this point in the history
Feat/c32 optimizations
  • Loading branch information
zone117x authored Apr 20, 2022
2 parents 1e0b80b + b1061ef commit d2f31ca
Show file tree
Hide file tree
Showing 6 changed files with 500 additions and 71 deletions.
4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ harness = false
name = "block_limits"
harness = false

[[bench]]
name = "c32_bench"
harness = false

[dependencies]
rand = "0.7.3"
rand_chacha = "=0.2.2"
Expand Down
35 changes: 35 additions & 0 deletions benches/c32_bench.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
extern crate blockstack_lib;
extern crate criterion;
extern crate rand;

use blockstack_lib::address::c32::{c32_address, c32_address_decode};
use blockstack_lib::address::c32_old::c32_address_decode as c32_address_decode_old;
use criterion::{criterion_group, criterion_main, BenchmarkId, Criterion};
use rand::Rng;

fn bench_c32_decoding(c: &mut Criterion) {
let mut group = c.benchmark_group("C32 Decoding");

let mut addrs: Vec<String> = vec![];
for _ in 0..5 {
// random version
let random_version: u8 = rand::thread_rng().gen_range(0, 31);
// random 20 bytes
let random_bytes = rand::thread_rng().gen::<[u8; 20]>();
let addr = c32_address(random_version, &random_bytes).unwrap();
addrs.push(addr);
}

for addr in addrs.iter() {
group.bench_with_input(BenchmarkId::new("Legacy", addr), addr, |b, i| {
b.iter(|| c32_address_decode_old(i))
});
group.bench_with_input(BenchmarkId::new("Updated", addr), addr, |b, i| {
b.iter(|| c32_address_decode(i))
});
}
group.finish();
}

criterion_group!(benches, bench_c32_decoding);
criterion_main!(benches);
Loading

0 comments on commit d2f31ca

Please sign in to comment.