Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

The Rust code was very non-idiomatic, and is dramatically disadvantaged by using the ISAAC random number generator (which is cryptographically secure, and so quite slow). By rewriting it to use more iterators (for non-bounds checked vector access), more vector-building functions (specifically, `vec::with_capacity` and `vec::from_fn`), and a non-cryptographically secure RNG[1], I get the following:

  Rust       0.34
  Rust isaac 0.57
  Rust orig  0.70
  Clang      0.42
  GCC        0.36
My rewritten version: https://github.com/huonw/levgen-benchmarks/blob/master/R.rs (I didn't bother implementing seeding of the RNG for this, so it's the same result every time. Edit: implemented now, no performance change.)

[1]: The new RNG is XorShiftRng, which is also in the standard library, and actually has far better randomness properties than most platforms' `rand()` functions anyway.

(Edit: merging two adjacent `if` statements, took it down to 0.34 from 0.36.)



Here's the compare view for an overview of the changes dbaupp applied to the original code: https://github.com/huonw/levgen-benchmarks/compare/logicchai...

edit: wrong addition left thereafter for posterity, ignore it (apparently Go uses ISAAC so the change to XorShiftRng might be unfair to Go (though it's trailing anyway). I expect C uses the standard libc generator?)


Assuming this [1] is what Go is using, it is not ISAAC. It looks like a lagged Fibonacci generator.

[1] http://golang.org/src/pkg/math/rand/rng.go


Ah yes, I misread a comment below which talked about Go and Rust, I didn't read closely enough and took the ISAAC mention to apply to Go.


(This is now the code in the article.)




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: