Created
March 17, 2017 18:36
-
-
Save LivingInSyn/4c1c28632ac4c27cff4c243e11d39c3e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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