mirror of
https://github.com/sigp/lighthouse.git
synced 2026-05-02 04:03:35 +00:00
Update SszEncoder
This commit is contained in:
32
eth2/utils/ssz/examples/large_list_of_structs.rs
Normal file
32
eth2/utils/ssz/examples/large_list_of_structs.rs
Normal file
@@ -0,0 +1,32 @@
|
||||
//! Encode and decode a list many times.
|
||||
//!
|
||||
//! Useful for `cargo flamegraph`.
|
||||
|
||||
use ssz::{Decodable, Encodable};
|
||||
use ssz_derive::{Decode, Encode};
|
||||
|
||||
#[derive(Clone, Copy, Encode, Decode)]
|
||||
pub struct FixedLen {
|
||||
a: u64,
|
||||
b: u64,
|
||||
c: u64,
|
||||
d: u64,
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let fixed_len = FixedLen {
|
||||
a: 42,
|
||||
b: 42,
|
||||
c: 42,
|
||||
d: 42,
|
||||
};
|
||||
|
||||
let vec: Vec<FixedLen> = vec![fixed_len; 8196];
|
||||
|
||||
let output: Vec<Vec<u64>> = (0..40_000)
|
||||
.into_iter()
|
||||
.map(|_| Vec::from_ssz_bytes(&vec.as_ssz_bytes()).unwrap())
|
||||
.collect();
|
||||
|
||||
println!("{}", output.len());
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
use ssz::{Decodable, DecodeError, Encodable, SszDecoderBuilder, SszEncoder, SszStream};
|
||||
use ssz::{Decodable, DecodeError, Encodable, SszDecoderBuilder, SszEncoder};
|
||||
|
||||
#[derive(Debug, PartialEq)]
|
||||
pub struct Foo {
|
||||
@@ -23,7 +23,7 @@ impl Encodable for Foo {
|
||||
encoder.append(&self.b);
|
||||
encoder.append(&self.c);
|
||||
|
||||
buf.append(&mut encoder.drain());
|
||||
encoder.drain_onto(buf);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user