- 
                Notifications
    You must be signed in to change notification settings 
- Fork 13.9k
Closed
Description
I just implemented the code in section 3.3 to compare Ruby to Rust. It appears that rustc optimizes away the inner loop of the thread, because I kept increasing the limit and the completion time remained constant. I introduced a simple if statement in the loop, and then I got expected timings.
It might be worth modifying the loop so it's not optimized away for a fairer comparison. Here's what I ended up with:
pub extern fn process() {
  let handles: Vec<_> = (0..10).map(|_| {
    thread::spawn(|| {
      let mut x = 0u64;
      for i in (0..7_700_000_000u64) {
        if i < 1 {
          x += 2
        } else {
          x += 1
        }
      }
      x
    })
  }).collect();
  for h in handles {
    println!("Thread finished with count={}",
             h.join().map_err(|_| "Could not join a thread!").unwrap());
  }
  println!("done!");
}
Metadata
Metadata
Assignees
Labels
No labels