{"action":"created","issue":{"url":"https://api.github.com/repos/rust-lang/rust/issues/28713","labels_url":"https://api.github.com/repos/rust-lang/rust/issues/28713/labels{/name}","comments_url":"https://api.github.com/repos/rust-lang/rust/issues/28713/comments","events_url":"https://api.github.com/repos/rust-lang/rust/issues/28713/events","html_url":"https://github.com/rust-lang/rust/issues/28713","id":108741616,"number":28713,"title":"rustc apparently optimizes away the loop in 3.3","user":{"login":"lojic","id":57366,"avatar_url":"https://avatars.githubusercontent.com/u/57366?v=3","gravatar_id":"","url":"https://api.github.com/users/lojic","html_url":"https://github.com/lojic","followers_url":"https://api.github.com/users/lojic/followers","following_url":"https://api.github.com/users/lojic/following{/other_user}","gists_url":"https://api.github.com/users/lojic/gists{/gist_id}","starred_url":"https://api.github.com/users/lojic/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lojic/subscriptions","organizations_url":"https://api.github.com/users/lojic/orgs","repos_url":"https://api.github.com/users/lojic/repos","events_url":"https://api.github.com/users/lojic/events{/privacy}","received_events_url":"https://api.github.com/users/lojic/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/rust-lang/rust/labels/A-docs","name":"A-docs","color":"d7e102"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":5,"created_at":"2015-09-28T20:38:57Z","updated_at":"2015-09-28T20:49:15Z","closed_at":null,"body":"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.\r\n\r\nIt might be worth modifying the loop so it's not optimized away for a fairer comparison. Here's what I ended up with:\r\n\r\n```\r\npub extern fn process() {\r\n  let handles: Vec<_> = (0..10).map(|_| {\r\n    thread::spawn(|| {\r\n      let mut x = 0u64;\r\n      for i in (0..7_700_000_000u64) {\r\n        if i < 1 {\r\n          x += 2\r\n        } else {\r\n          x += 1\r\n        }\r\n      }\r\n      x\r\n    })\r\n  }).collect();\r\n\r\n  for h in handles {\r\n    println!(\"Thread finished with count={}\",\r\n             h.join().map_err(|_| \"Could not join a thread!\").unwrap());\r\n  }\r\n  println!(\"done!\");\r\n}\r\n```\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/rust-lang/rust/issues/comments/143869696","html_url":"https://github.com/rust-lang/rust/issues/28713#issuecomment-143869696","issue_url":"https://api.github.com/repos/rust-lang/rust/issues/28713","id":143869696,"user":{"login":"lojic","id":57366,"avatar_url":"https://avatars.githubusercontent.com/u/57366?v=3","gravatar_id":"","url":"https://api.github.com/users/lojic","html_url":"https://github.com/lojic","followers_url":"https://api.github.com/users/lojic/followers","following_url":"https://api.github.com/users/lojic/following{/other_user}","gists_url":"https://api.github.com/users/lojic/gists{/gist_id}","starred_url":"https://api.github.com/users/lojic/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lojic/subscriptions","organizations_url":"https://api.github.com/users/lojic/orgs","repos_url":"https://api.github.com/users/lojic/repos","events_url":"https://api.github.com/users/lojic/events{/privacy}","received_events_url":"https://api.github.com/users/lojic/received_events","type":"User","site_admin":false},"created_at":"2015-09-28T20:49:15Z","updated_at":"2015-09-28T20:49:15Z","body":"Sorry, missed \"nightly\" above - I'll check that..."}}