mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-26 19:17:58 +00:00
b581604aa7
* Apply some clippy hints * Revert clippy ci changes * Update client/cli/src/commands/generate.rs Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com> * Update client/cli/src/commands/inspect_key.rs Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com> * Update client/db/src/bench.rs Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com> * Update client/db/src/bench.rs Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com> * Update client/service/src/client/block_rules.rs Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com> * Update client/service/src/client/block_rules.rs Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com> * Update client/network/src/transactions.rs Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com> * Update client/network/src/protocol.rs Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com> * Revert due to missing `or_default` function. * Fix compilation and simplify code * Undo change that corrupts benchmark. * fix clippy * Update client/service/test/src/lib.rs Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com> * Update client/state-db/src/noncanonical.rs Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com> * Update client/state-db/src/noncanonical.rs remove leftovers! * Update client/tracing/src/logging/directives.rs Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com> * Update utils/fork-tree/src/lib.rs Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com> * added needed ref * Update frame/referenda/src/benchmarking.rs * Simplify byte-vec creation * let's just not overlap the ranges * Correction * cargo fmt * Update utils/frame/benchmarking-cli/src/shared/stats.rs Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com> * Update utils/frame/benchmarking-cli/src/pallet/command.rs Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com> * Update utils/frame/benchmarking-cli/src/pallet/command.rs Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com> Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com> Co-authored-by: Giles Cope <gilescope@gmail.com>
82 lines
2.4 KiB
Rust
82 lines
2.4 KiB
Rust
// This file is part of Substrate.
|
|
|
|
// Copyright (C) 2019-2022 Parity Technologies (UK) Ltd.
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
// you may not use this file except in compliance with the License.
|
|
// You may obtain a copy of the License at
|
|
//
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
//
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
// See the License for the specific language governing permissions and
|
|
// limitations under the License.
|
|
|
|
use criterion::{criterion_group, criterion_main, BenchmarkId, Criterion, Throughput};
|
|
use rand::Rng;
|
|
use sp_arithmetic::biguint::{BigUint, Single};
|
|
|
|
fn random_big_uint(size: usize) -> BigUint {
|
|
let mut rng = rand::thread_rng();
|
|
let digits: Vec<_> = (0..size).map(|_| rng.gen_range(0, Single::max_value())).collect();
|
|
BigUint::from_limbs(&digits)
|
|
}
|
|
|
|
fn bench_op<F: Fn(&BigUint, &BigUint)>(c: &mut Criterion, name: &str, op: F) {
|
|
let mut group = c.benchmark_group(name);
|
|
|
|
for size in [2, 4, 6, 8, 10].iter() {
|
|
group.throughput(Throughput::Elements(*size));
|
|
group.bench_with_input(BenchmarkId::from_parameter(size), size, |bencher, &size| {
|
|
let a = random_big_uint(size as usize);
|
|
let b = random_big_uint(size as usize);
|
|
|
|
bencher.iter(|| op(&a, &b));
|
|
});
|
|
}
|
|
}
|
|
|
|
fn bench_addition(c: &mut Criterion) {
|
|
bench_op(c, "addition", |a, b| {
|
|
let _ = a.clone().add(b);
|
|
});
|
|
}
|
|
|
|
fn bench_subtraction(c: &mut Criterion) {
|
|
bench_op(c, "subtraction", |a, b| {
|
|
let _ = a.clone().sub(b);
|
|
});
|
|
}
|
|
|
|
fn bench_multiplication(c: &mut Criterion) {
|
|
bench_op(c, "multiplication", |a, b| {
|
|
let _ = a.clone().mul(b);
|
|
});
|
|
}
|
|
|
|
fn bench_division(c: &mut Criterion) {
|
|
let mut group = c.benchmark_group("division");
|
|
|
|
for size in [4, 6, 8, 10].iter() {
|
|
group.throughput(Throughput::Elements(*size));
|
|
group.bench_with_input(BenchmarkId::from_parameter(size), size, |bencher, &size| {
|
|
let a = random_big_uint(size as usize);
|
|
let b = random_big_uint(rand::thread_rng().gen_range(2, size as usize));
|
|
|
|
bencher.iter(|| {
|
|
let _ = a.clone().div(&b, true);
|
|
});
|
|
});
|
|
}
|
|
}
|
|
|
|
criterion_group! {
|
|
name = benches;
|
|
config = Criterion::default();
|
|
targets = bench_addition, bench_subtraction, bench_multiplication, bench_division
|
|
}
|
|
criterion_main!(benches);
|