4 stable releases

Uses old Rust 2015

1.3.0 Jun 27, 2020
1.2.1 Jun 27, 2020
1.2.0 Nov 21, 2017
1.0.0 Dec 10, 2016

#12 in #amd64

Download history 15/week @ 2024-03-12 11/week @ 2024-03-19 11/week @ 2024-03-26 29/week @ 2024-04-02 10/week @ 2024-04-09 10/week @ 2024-04-16 16/week @ 2024-04-23 10/week @ 2024-04-30 8/week @ 2024-05-07 7/week @ 2024-05-14 9/week @ 2024-05-21 9/week @ 2024-05-28 10/week @ 2024-06-04 13/week @ 2024-06-11 14/week @ 2024-06-18 13/week @ 2024-06-25

52 downloads per month
Used in 2 crates (via firestorm-core)

MIT license

10KB
201 lines

x86/x86_64 Timer

This is a low level CPU cycle count timer. What it returns is the value held within the processor time stamp counter. This counter is incremented every CPU cycle.

Considerations

When bench marking with this crate you want to assure your CPU is set to a fixed multipler. This mean Intel Turbo Boost must be OFF. You can do this in via the bios.

This crate requires Rust Nightly (as it uses llvm_asm! macro), you will need to enable !#[feature(llvm_asm)].

Functions

fn ticks() -> u64;

This returns the number of CPU cycles that have passed since the last time the CPU counter has rolled over. OR Power on.

In Depth Documentation

This function step by step:

#Intel Syntax

ldfence		#cheapest fence on x86
		    #this prevents instruction re-ordering
		    #ensures all loads are complete
		    #on x64 this is done for you by the memory model
		    #so this fence is _free_
		    #this fence is here to prevent speculative
		    #execution of rdtsc.

rdtsc		#puts timestamp counter values into the low
		    #32bits of rdx and rax.


shl rdx, $32	#move the high section, into the high 32bits of
		        #its register

or rax, rdx	#combine bits

retq		#leave function

Reference

License

Consider this crate licensed under the MIT.

x86 support

This crate does implement 32bit x86 support, but it is untested.

No runtime deps

~20KB