Skip to content

Instantly share code, notes, and snippets.

@huonw
Last active December 17, 2015 04:49
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save huonw/5553335 to your computer and use it in GitHub Desktop.
Save huonw/5553335 to your computer and use it in GitHub Desktop.
Rust > C[lang] for Mersenne Twister

This is wrong, Rust is not faster than GCC (but is sometimes faster than Clang), see this discussion

I implemented the Mersenne Twister random number generator in Rust, and then compared the Rust one with the fastest non-Rust one I could find (mt19937ar-cok.c on this page):

** Rust **
1040076681

real    0m4.470s
user    0m4.444s
sys     0m0.004s

1040076681

real    0m4.399s
user    0m4.384s
sys     0m0.004s

1040076681

real    0m4.347s
user    0m4.336s
sys     0m0.000s

** C **
1040076681

real    0m4.592s
user    0m4.568s
sys     0m0.000s

1040076681

real    0m4.516s
user    0m4.484s
sys     0m0.000s

1040076681

real    0m4.502s
user    0m4.488s
sys     0m0.004s

(Summing 1,000,000,000 random u32s. The Rust was compiled with rustc --opt-level=3 and the C gcc -O3.)

@Fuzion24
Copy link

Just curious, where is your implementation of the Mersenne Twister in Rust?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment