Skip to content

Commit

Permalink
use elapsed instead of duration_since for time measurements
Browse files Browse the repository at this point in the history
  • Loading branch information
Brechtpd committed Apr 11, 2024
1 parent 27bf1c3 commit 38840b6
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
9 changes: 3 additions & 6 deletions host/src/provider_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -326,26 +326,23 @@ impl Database for MeasuredProviderDb {
self.num_basic += 1;
let start = Instant::now();
let res = self.provider.basic(address);
self.time_basic
.add_assign(Instant::now().duration_since(start));
self.time_basic.add_assign(start.elapsed());
res
}

fn storage(&mut self, address: Address, index: U256) -> Result<U256, Self::Error> {
self.num_storage += 1;
let start = Instant::now();
let res = self.provider.storage(address, index);
self.time_storage
.add_assign(Instant::now().duration_since(start));
self.time_storage.add_assign(start.elapsed());
res
}

fn block_hash(&mut self, number: U256) -> Result<B256, Self::Error> {
self.num_block_hash += 1;
let start = Instant::now();
let res = self.provider.block_hash(number);
self.time_block_hash
.add_assign(Instant::now().duration_since(start));
self.time_block_hash.add_assign(start.elapsed());
res
}

Expand Down
4 changes: 2 additions & 2 deletions lib/src/builder/execute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ impl TxExecStrategy for TkoTxExecStrategy {
#[cfg(feature = "std")]
debug!(" Ok: {result:?}");

tx_transact_duration.add_assign(Instant::now().duration_since(start));
tx_transact_duration.add_assign(start.elapsed());

let start = Instant::now();

Expand Down Expand Up @@ -300,7 +300,7 @@ impl TxExecStrategy for TkoTxExecStrategy {
// If we got here it means the tx is not invalid
actual_tx_no += 1;

tx_misc_duration.add_assign(Instant::now().duration_since(start));
tx_misc_duration.add_assign(start.elapsed());
}
clear_line();
print_duration("Tx transact time: ", tx_transact_duration);
Expand Down
5 changes: 4 additions & 1 deletion lib/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ mod time {
pub fn duration_since(&self, _instant: Instant) -> Duration {
Duration::default()
}
pub fn elapsed(&self) -> Duration {
Duration::default()
}
}

#[derive(Default, Clone, Copy)]
Expand Down Expand Up @@ -111,7 +114,7 @@ impl Measurement {
}

pub fn stop_with(&self, title: &str) -> time::Duration {
let time_elapsed = time::Instant::now().duration_since(self.start);
let time_elapsed = self.start.elapsed();
print_duration(
&format!("{}{} in ", if self.inplace { "\r" } else { "" }, title,),
time_elapsed,
Expand Down

0 comments on commit 38840b6

Please sign in to comment.