Skip to content

Instantly share code, notes, and snippets.

@LivingInSyn
Created March 17, 2017 18:36
Show Gist options
  • Save LivingInSyn/4c1c28632ac4c27cff4c243e11d39c3e to your computer and use it in GitHub Desktop.
Save LivingInSyn/4c1c28632ac4c27cff4c243e11d39c3e to your computer and use it in GitHub Desktop.
extern crate time;
extern crate rand;
use time::PreciseTime;
use rand::Rng;
fn main() {
for n in 0..101{
let start_double_shift = PreciseTime::now();
for n in 0..101 {
let num = rand::thread_rng().gen_range(0, 255);
//get the value of the third bit with 2 shifts
let val = num << 6 >> 7;
}
let end_double_shift = PreciseTime::now();
//println!("Start: {}", start_double_shift.to(end_double_shift));
let start_and_shift = PreciseTime::now();
for n in 0..101 {
let num = rand::thread_rng().gen_range(0, 255);
//get the value of the third bit with an AND and 1 shift
let val = (num & 0x04) >> 2;
}
let end_and_shift = PreciseTime::now();
println!("{},{},{}",n,start_double_shift.to(end_double_shift),start_and_shift.to(end_and_shift));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment