cputicks 0.1.0

Cross-platform cycle tick counter with runtime auto-selection
Documentation
  • Coverage
  • 100%
    21 out of 21 items documented5 out of 19 items with examples
  • Size
  • Source code size: 67.7 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 2.42 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 48s Average build duration of successful builds.
  • all releases: 48s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • spence/cputicks
    1 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • spence

cputicks

A Rust port of libcpucycles for high-resolution timing.

Provides sub-nanosecond timing by directly reading hardware counters (RDTSC, CNTVCT_EL0, etc.) with automatic runtime selection of the best available source. ~30x faster than std::time::Instant.

use cputicks::Ticks;

let start = Ticks::now();
// ... work ...
println!("{:?}", start.elapsed().as_duration());

println!("Using: {} @ {} Hz", Ticks::implementation(), Ticks::frequency());

CLI

$ cargo run --bin cputicks --release
cputicks v0.1.0

Implementation: aarch64-cntvct
Frequency:      24000000 Hz (24.00 MHz)
Overhead:       650 ps per call
Resolution:     0 ticks (0 ps)

Platform Support

Architecture Primary Fallback
x86_64 ✓ RDTSC ✓ OS timer
x86 ✓ RDTSC ✓ OS timer
aarch64 ✓ CNTVCT_EL0 ✓ OS timer
aarch64 (Linux) ✓ PMCCNTR_EL0 ✓ CNTVCT_EL0
riscv64 ✓ rdcycle ✓ OS timer
powerpc64 ✓ mftb ✓ OS timer
s390x ✓ stckf ✓ OS timer
loongarch64 ✓ rdtime.d ✓ OS timer
other ✓ OS timer

OS timers: mach_absolute_time (macOS), clock_gettime (Unix), Instant (other)

Benchmarks

Apple M1 (aarch64-cntvct @ 24 MHz):

Operation Time
Ticks::now() 658 ps
Ticks::now() + elapsed() 882 ps
std::time::Instant::now() 20.0 ns
std::time::Instant (now + elapsed) 43.3 ns