1use reth_primitives_traits::FastInstant as Instant;
2use std::time::Duration;
3
4#[derive(Clone, Copy, Debug)]
6pub struct TrieStats {
7 duration: Duration,
8 branches_added: u64,
9 leaves_added: u64,
10}
11
12impl TrieStats {
13 pub const fn duration(&self) -> Duration {
15 self.duration
16 }
17
18 pub const fn leaves_added(&self) -> u64 {
20 self.leaves_added
21 }
22
23 pub const fn branches_added(&self) -> u64 {
25 self.branches_added
26 }
27}
28
29#[derive(Debug)]
31pub struct TrieTracker {
32 started_at: Instant,
33 branches_added: u64,
34 leaves_added: u64,
35}
36
37impl Default for TrieTracker {
38 fn default() -> Self {
39 Self { started_at: Instant::now(), branches_added: 0, leaves_added: 0 }
40 }
41}
42
43impl TrieTracker {
44 pub const fn inc_branch(&mut self) {
46 self.branches_added += 1;
47 }
48
49 pub const fn inc_leaf(&mut self) {
51 self.leaves_added += 1;
52 }
53
54 pub fn finish(self) -> TrieStats {
56 TrieStats {
57 duration: self.started_at.elapsed(),
58 branches_added: self.branches_added,
59 leaves_added: self.leaves_added,
60 }
61 }
62}