Advertisement
Guest User

Untitled

a guest
Aug 19th, 2019
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.56 KB | None | 0 0
  1. use std::time::{Instant, Duration};
  2. use std::sync::atomic::spin_loop_hint;
  3.  
  4. pub fn main() {
  5. let mut last = Instant::now();
  6. let mut counter = 0;
  7.  
  8. loop {
  9. counter += 1;
  10.  
  11. let mut now = Instant::now();
  12.  
  13. if counter % 10000 == 0 {
  14. let now = Instant::now();
  15. let diff = now - last;
  16. println!("{}", diff.as_nanos());
  17. }
  18.  
  19. while (now - last) < Duration::from_nanos(186) {
  20. spin_loop_hint();
  21. now = Instant::now();
  22. }
  23. last = now;
  24. }
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement