Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

improve run_benchmark #13935

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions bin/node/bench/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ fs_extra = "1"
rand = { version = "0.8.5", features = ["small_rng"] }
lazy_static = "1.4.0"
parity-db = "0.4.6"
rayon = "1.7"
sc-transaction-pool = { version = "4.0.0-dev", path = "../../../client/transaction-pool" }
sc-transaction-pool-api = { version = "4.0.0-dev", path = "../../../client/transaction-pool/api" }
futures = { version = "0.3.21", features = ["thread-pool"] }
21 changes: 13 additions & 8 deletions bin/node/bench/src/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
// along with this program. If not, see <https://www.gnu.org/licenses/>.

use serde::Serialize;
use rayon::prelude::*;
use std::{
borrow::{Cow, ToOwned},
fmt,
Expand Down Expand Up @@ -126,18 +127,22 @@ pub fn run_benchmark(benchmark: Box<dyn BenchmarkDescription>, mode: Mode) -> Be
let name = benchmark.name().to_owned();
let mut benchmark = benchmark.setup();

let mut durations: Vec<u128> = vec![];
for _ in 0..50 {
let duration = benchmark.run(mode);
durations.push(duration.as_nanos());
}
let durations: Vec<u128> = (0..50)
.into_par_iter()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These benches run serially since they otherwise influence each other.

Also this code is pretty dated and should eventually be removed (https://github.com/paritytech/substrate/issues/12218).

.map(|_| benchmark.run(mode).as_nanos())
.collect();

durations.sort();
let mut sorted_durations = durations.clone();
sorted_durations.par_sort_unstable();

let raw_average = (durations.iter().sum::<u128>() / (durations.len() as u128)) as u64;
let average = (durations.iter().skip(10).take(30).sum::<u128>() / 30) as u64;
let average = (sorted_durations.iter().skip(10).take(30).sum::<u128>() / 30) as u64;

BenchmarkOutput { name: name.into(), raw_average, average }
BenchmarkOutput {
name: name.into(),
raw_average,
average,
}
}

macro_rules! matrix(
Expand Down