Add profiling tools, examples

This commit is contained in:
Paul Hauner 2019-05-05 15:32:09 +10:00
parent fd5f914c3c
commit acf854f558
No known key found for this signature in database
GPG Key ID: 303E4494BB28068C
5 changed files with 81 additions and 19 deletions

View File

@ -36,3 +36,6 @@ members = [
"validator_client", "validator_client",
"account_manager", "account_manager",
] ]
[profile.release]
debug = true

View File

@ -4,7 +4,12 @@ version = "0.1.0"
authors = ["Paul Hauner <paul@paulhauner.com>"] authors = ["Paul Hauner <paul@paulhauner.com>"]
edition = "2018" edition = "2018"
[[bench]]
name = "benches"
harness = false
[dev-dependencies] [dev-dependencies]
criterion = "0.2"
ssz_derive = { path = "../ssz_derive" } ssz_derive = { path = "../ssz_derive" }
[dependencies] [dependencies]

View File

@ -0,0 +1,38 @@
#[macro_use]
extern crate criterion;
use criterion::black_box;
use criterion::{Benchmark, Criterion};
use ssz::{Decodable, Encodable};
fn criterion_benchmark(c: &mut Criterion) {
let n = 8196;
let vec: Vec<u64> = vec![4242; 8196];
c.bench(
&format!("vec_of_{}_u64", n),
Benchmark::new("as_ssz_bytes", move |b| {
b.iter_with_setup(|| vec.clone(), |vec| black_box(vec.as_ssz_bytes()))
})
.sample_size(100),
);
let vec: Vec<u64> = vec![4242; 8196];
let bytes = vec.as_ssz_bytes();
c.bench(
&format!("vec_of_{}_u64", n),
Benchmark::new("from_ssz_bytes", move |b| {
b.iter_with_setup(
|| bytes.clone(),
|bytes| {
let vec: Vec<u64> = Vec::from_ssz_bytes(&bytes).unwrap();
black_box(vec)
},
)
})
.sample_size(100),
);
}
criterion_group!(benches, criterion_benchmark);
criterion_main!(benches);

View File

@ -0,0 +1,16 @@
//! Encode and decode a list 10,000 times.
//!
//! Useful for `cargo flamegraph`.
use ssz::{Decodable, Encodable};
fn main() {
let vec: Vec<u64> = vec![4242; 8196];
let output: Vec<Vec<u64>> = (0..10_000)
.into_iter()
.map(|_| Vec::from_ssz_bytes(&vec.as_ssz_bytes()).unwrap())
.collect();
println!("{}", output.len());
}