Skip to content

sheroz/tick_counter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

70 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Hardware-based tick counters for high-precision benchmarks

crates.io docs build & test license

  • x86_64: executes RDTSC CPU instruction to read the time-stamp counter.
  • AArch64: reads value of the CNTVCT_EL0 counter-timer register.

The brief description: https://sheroz.com/pages/blog/rust-tick-counter.html

Tested on platforms

x86_64 (Intel® Core™ i7)
AArch64 (Apple M1 Pro)

Usage

For usage samples please look at src/bin/sample.rs

Basic usage

let start = tick_counter::start();
// ... lines of code to benchmark
let elapsed_ticks = tick_counter::stop() - start;
println!("Number of elapsed ticks: {}", elapsed_ticks);

Basic usage with helper

use tick_counter::TickCounter;
 
let tick_counter = TickCounter::current();
// ... lines of code to benchmark
let elapsed_ticks = tick_counter.elapsed();
println!("Number of elapsed ticks: {}", elapsed_ticks);

Extended usage

println!("Environment: {}/{} {}", consts::OS, consts::FAMILY, consts::ARCH);

let (counter_frequency, accuracy) = tick_counter::frequency();
let frequency_base = match accuracy {
    tick_counter::TickCounterFrequencyBase::Hardware => "hardware provided".to_string(),
    tick_counter::TickCounterFrequencyBase::Measured(duration) => format!(