{"action":"created","issue":{"url":"https://api.github.com/repos/rust-lang/rand/issues/59","labels_url":"https://api.github.com/repos/rust-lang/rand/issues/59/labels{/name}","comments_url":"https://api.github.com/repos/rust-lang/rand/issues/59/comments","events_url":"https://api.github.com/repos/rust-lang/rand/issues/59/events","html_url":"https://github.com/rust-lang/rand/pull/59","id":95661005,"number":59,"title":"Faster and Better weak generators","user":{"login":"arthurprs","id":715958,"avatar_url":"https://avatars.githubusercontent.com/u/715958?v=3","gravatar_id":"","url":"https://api.github.com/users/arthurprs","html_url":"https://github.com/arthurprs","followers_url":"https://api.github.com/users/arthurprs/followers","following_url":"https://api.github.com/users/arthurprs/following{/other_user}","gists_url":"https://api.github.com/users/arthurprs/gists{/gist_id}","starred_url":"https://api.github.com/users/arthurprs/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/arthurprs/subscriptions","organizations_url":"https://api.github.com/users/arthurprs/orgs","repos_url":"https://api.github.com/users/arthurprs/repos","events_url":"https://api.github.com/users/arthurprs/events{/privacy}","received_events_url":"https://api.github.com/users/arthurprs/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":{"login":"alexcrichton","id":64996,"avatar_url":"https://avatars.githubusercontent.com/u/64996?v=3","gravatar_id":"","url":"https://api.github.com/users/alexcrichton","html_url":"https://github.com/alexcrichton","followers_url":"https://api.github.com/users/alexcrichton/followers","following_url":"https://api.github.com/users/alexcrichton/following{/other_user}","gists_url":"https://api.github.com/users/alexcrichton/gists{/gist_id}","starred_url":"https://api.github.com/users/alexcrichton/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alexcrichton/subscriptions","organizations_url":"https://api.github.com/users/alexcrichton/orgs","repos_url":"https://api.github.com/users/alexcrichton/repos","events_url":"https://api.github.com/users/alexcrichton/events{/privacy}","received_events_url":"https://api.github.com/users/alexcrichton/received_events","type":"User","site_admin":false},"milestone":null,"comments":3,"created_at":"2015-07-17T13:57:34Z","updated_at":"2015-07-17T18:31:14Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/rust-lang/rand/pulls/59","html_url":"https://github.com/rust-lang/rand/pull/59","diff_url":"https://github.com/rust-lang/rand/pull/59.diff","patch_url":"https://github.com/rust-lang/rand/pull/59.patch"},"body":"I took a couple of days to research some fast pseudo-random number generators and I thought it'd be nice to contribute to the crate.\r\n\r\nThis PR contains two commits one adding the xorshift128+ and the other PCG RXS M XS (32 and 64bit variants). I don't think there's precedence for adding both, so I think we should discuss how to proceed.\r\n\r\n| Algorithm    | Size     | Quality | x86 (u32) | x86 (u64) | x64 (u32) | x64 (u64) |\r\n|--------------|----------|---------|-----------|-----------|-----------|-----------|\r\n| PCG32        | 4 Bytes  | Fair    | 1365      | 1616      | 1646      | 1677      |\r\n| PCG64        | 8 Bytes  | Great   | 510       | 1016      | 1646      | 3493      |\r\n| Xorshift64   | 16 Bytes | Bad     | 1486      | 1895      | 2094      | 2279      |\r\n| Xorshift128+ | 16 Bytes | Great   | 911       | 1656      | 2000      | 4278      |\r\n\r\nx64 benchmarks (my laptop)\r\n```\r\ntest algorithms::chacha_u32                        ... bench:       2,477 ns/iter (+/- 191) = 161 MB/s\r\ntest algorithms::chacha_u64                        ... bench:       4,783 ns/iter (+/- 353) = 167 MB/s\r\ntest algorithms::isaac64_u32                       ... bench:         617 ns/iter (+/- 40) = 648 MB/s\r\ntest algorithms::isaac64_u64                       ... bench:         639 ns/iter (+/- 16) = 1251 MB/s\r\ntest algorithms::isaac_u32                         ... bench:         847 ns/iter (+/- 30) = 472 MB/s\r\ntest algorithms::isaac_u64                         ... bench:       1,579 ns/iter (+/- 130) = 506 MB/s\r\ntest algorithms::pcg32_u32                         ... bench:         243 ns/iter (+/- 10) = 1646 MB/s\r\ntest algorithms::pcg32_u64                         ... bench:         477 ns/iter (+/- 23) = 1677 MB/s\r\ntest algorithms::pcg64_u32                         ... bench:         243 ns/iter (+/- 14) = 1646 MB/s\r\ntest algorithms::pcg64_u64                         ... bench:         229 ns/iter (+/- 16) = 3493 MB/s\r\ntest algorithms::xorshift_u32                      ... bench:         191 ns/iter (+/- 11) = 2094 MB/s\r\ntest algorithms::xorshift_u64                      ... bench:         351 ns/iter (+/- 18) = 2279 MB/s\r\ntest algorithms::xorshiftp_u32                     ... bench:         200 ns/iter (+/- 11) = 2000 MB/s\r\ntest algorithms::xorshiftp_u64                     ... bench:         187 ns/iter (+/- 7) = 4278 MB/s\r\n\r\n```\r\nx86 benchmarks (DO)\r\n```\r\ntest algorithms::chacha_u32                        ... bench:       2,644 ns/iter (+/- 21) = 151 MB/s\r\ntest algorithms::chacha_u64                        ... bench:       4,964 ns/iter (+/- 28) = 161 MB/s\r\ntest algorithms::isaac64_u32                       ... bench:       1,038 ns/iter (+/- 8) = 385 MB/s\r\ntest algorithms::isaac64_u64                       ... bench:       1,059 ns/iter (+/- 6) = 755 MB/s\r\ntest algorithms::isaac_u32                         ... bench:       1,107 ns/iter (+/- 12) = 361 MB/s\r\ntest algorithms::isaac_u64                         ... bench:       2,004 ns/iter (+/- 13) = 399 MB/s\r\ntest algorithms::pcg32_u32                         ... bench:         293 ns/iter (+/- 4) = 1365 MB/s\r\ntest algorithms::pcg32_u64                         ... bench:         495 ns/iter (+/- 6) = 1616 MB/s\r\ntest algorithms::pcg64_u32                         ... bench:         783 ns/iter (+/- 15) = 510 MB/s\r\ntest algorithms::pcg64_u64                         ... bench:         787 ns/iter (+/- 9) = 1016 MB/s\r\ntest algorithms::xorshift_u32                      ... bench:         269 ns/iter (+/- 4) = 1486 MB/s\r\ntest algorithms::xorshift_u64                      ... bench:         422 ns/iter (+/- 6) = 1895 MB/s\r\ntest algorithms::xorshiftp_u32                     ... bench:         439 ns/iter (+/- 7) = 911 MB/s\r\ntest algorithms::xorshiftp_u64                     ... bench:         483 ns/iter (+/- 5) = 1656 MB/s\r\n```\r\n\r\nPCG is neat, it's very compact and provide good quality, even in the 32bit variant!\r\n\r\nAlthough my preference would be to add the xorshift128+ variant and leave the xorshift64 there (probably worth a rename though).\r\n\r\nIn addition weak_rng should return the fastest algorithm available for the architectures. As 64bit operations kills performance in 32bit architectures this can be as simple as Xorshift64 for 32bit and Xorshift128+ for 64bit.\r\n\r\nFinally, users won't need to look elsewhere for a crazy fast random implementation.\r\n\r\nThoughts?"},"comment":{"url":"https://api.github.com/repos/rust-lang/rand/issues/comments/122366814","html_url":"https://github.com/rust-lang/rand/pull/59#issuecomment-122366814","issue_url":"https://api.github.com/repos/rust-lang/rand/issues/59","id":122366814,"user":{"login":"alexcrichton","id":64996,"avatar_url":"https://avatars.githubusercontent.com/u/64996?v=3","gravatar_id":"","url":"https://api.github.com/users/alexcrichton","html_url":"https://github.com/alexcrichton","followers_url":"https://api.github.com/users/alexcrichton/followers","following_url":"https://api.github.com/users/alexcrichton/following{/other_user}","gists_url":"https://api.github.com/users/alexcrichton/gists{/gist_id}","starred_url":"https://api.github.com/users/alexcrichton/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alexcrichton/subscriptions","organizations_url":"https://api.github.com/users/alexcrichton/orgs","repos_url":"https://api.github.com/users/alexcrichton/repos","events_url":"https://api.github.com/users/alexcrichton/events{/privacy}","received_events_url":"https://api.github.com/users/alexcrichton/received_events","type":"User","site_admin":false},"created_at":"2015-07-17T18:31:14Z","updated_at":"2015-07-17T18:31:14Z","body":"r? @huonw, you may have more opinions on this than I\r\n\r\n> The “for the platform” is a pretty hard thing to do ­– we don’t want to start benchmarking all the xorshifts at runtime, nor do we want to make weak_rng to return XorShift on some platforms and XorShift+ on others. Therefore we have to rely on eyeballing and pick an algorithm that seems to be fast(est) on as many platforms as possible (our current pick being XorShift). \r\n\r\nWhile I agree we don't want to determine the fastest one at runtime, I do think that we should change the return type of `weak_rng` to `WeakRng` to hide the implementation. That way we can swap it out on various platforms and also change it in the future (like we want to right now) without breaking code. \r\n\r\nFor now I'd avoid changing `weak_rng` as this crate will likely have a number of other breaking changes coming soon, and it probably isn't worth the breakage just yet."}}