Add profiling tools, examples
This commit is contained in:
parent
fd5f914c3c
commit
acf854f558
@ -36,3 +36,6 @@ members = [
|
|||||||
"validator_client",
|
"validator_client",
|
||||||
"account_manager",
|
"account_manager",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[profile.release]
|
||||||
|
debug = true
|
||||||
|
@ -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]
|
||||||
|
38
eth2/utils/ssz/benches/benches.rs
Normal file
38
eth2/utils/ssz/benches/benches.rs
Normal 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);
|
16
eth2/utils/ssz/examples/large_list.rs
Normal file
16
eth2/utils/ssz/examples/large_list.rs
Normal 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());
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user