mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-07-21 14:25:41 +00:00
Move cryptographic hashing procedures to crypto folder. (#2306)
Step towards https://github.com/paritytech/polkadot-sdk/issues/1975 As reported https://github.com/paritytech/polkadot-sdk/issues/1975#issuecomment-1774534225 I'd like to encapsulate crypto related stuff in a dedicated folder. Currently all cryptographic primitive wrappers are all sparsed in `substrate/core` which contains "misc core" stuff. To simplify the process, as the first step with this PR I propose to move the cryptographic hashing there. The `substrate/crypto` folder was already created to contains `ec-utils` crate. Notes: - rename `sp-core-hashing` to `sp-crypto-hashing` - rename `sp-core-hashing-proc-macro` to `sp-crypto-hashing-proc-macro` - As the crates name is changed I took the freedom to restart fresh from version 0.1.0 for both crates --------- Co-authored-by: Robert Hambrock <roberthambrock@gmail.com>
This commit is contained in:
@@ -12,66 +12,8 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
use criterion::{black_box, criterion_group, criterion_main, Bencher, BenchmarkId, Criterion};
|
||||
use sp_core::{
|
||||
crypto::Pair as _,
|
||||
hashing::{blake2_128, twox_128},
|
||||
};
|
||||
|
||||
const MAX_KEY_SIZE: u32 = 32;
|
||||
|
||||
fn get_key(key_size: u32) -> Vec<u8> {
|
||||
use rand::{Rng, SeedableRng};
|
||||
|
||||
let rnd: [u8; 32] = rand::rngs::StdRng::seed_from_u64(12).gen();
|
||||
let mut rnd = rnd.iter().cycle();
|
||||
|
||||
(0..key_size).map(|_| *rnd.next().unwrap()).collect()
|
||||
}
|
||||
|
||||
fn bench_blake2_128(b: &mut Bencher, key: &Vec<u8>) {
|
||||
b.iter(|| {
|
||||
let _a = blake2_128(black_box(key));
|
||||
});
|
||||
}
|
||||
|
||||
fn bench_twox_128(b: &mut Bencher, key: &Vec<u8>) {
|
||||
b.iter(|| {
|
||||
let _a = twox_128(black_box(key));
|
||||
});
|
||||
}
|
||||
|
||||
fn bench_hash_128_fix_size(c: &mut Criterion) {
|
||||
let mut group = c.benchmark_group("fix size hashing");
|
||||
|
||||
let key = get_key(MAX_KEY_SIZE);
|
||||
|
||||
group.bench_with_input("blake2_128", &key, bench_blake2_128);
|
||||
group.bench_with_input("twox_128", &key, bench_twox_128);
|
||||
|
||||
group.finish();
|
||||
}
|
||||
|
||||
fn bench_hash_128_dyn_size(c: &mut Criterion) {
|
||||
let mut group = c.benchmark_group("dyn size hashing");
|
||||
|
||||
for i in (2..MAX_KEY_SIZE).step_by(4) {
|
||||
let key = get_key(i);
|
||||
|
||||
group.bench_with_input(
|
||||
BenchmarkId::new("blake2_128", format!("{}", i)),
|
||||
&key,
|
||||
bench_blake2_128,
|
||||
);
|
||||
group.bench_with_input(
|
||||
BenchmarkId::new("twox_128", format!("{}", i)),
|
||||
&key,
|
||||
bench_twox_128,
|
||||
);
|
||||
}
|
||||
|
||||
group.finish();
|
||||
}
|
||||
use criterion::{criterion_group, criterion_main, BenchmarkId, Criterion};
|
||||
use sp_core::crypto::Pair as _;
|
||||
|
||||
fn bench_ed25519(c: &mut Criterion) {
|
||||
let mut group = c.benchmark_group("ed25519");
|
||||
@@ -145,12 +87,5 @@ fn bench_ecdsa(c: &mut Criterion) {
|
||||
group.finish();
|
||||
}
|
||||
|
||||
criterion_group!(
|
||||
benches,
|
||||
bench_hash_128_fix_size,
|
||||
bench_hash_128_dyn_size,
|
||||
bench_ed25519,
|
||||
bench_sr25519,
|
||||
bench_ecdsa,
|
||||
);
|
||||
criterion_group!(benches, bench_ed25519, bench_sr25519, bench_ecdsa,);
|
||||
criterion_main!(benches);
|
||||
|
||||
Reference in New Issue
Block a user