Closed airstruck closed 7 years ago
MWC has speed comparable to Alea, since it doesn't use bit ops either (Alea is based on MWC). Unless anyone is particularly attached to LCG or Twister, I'd propose something like this:
Another Alea implementation is here, with more detailed explanation of some parts in the comments.
Fixed with 5d939011ff93dd796f6cfa4db73de686a0820c4c
Again, thanks for all of your contributions!
Summary:
It takes a while to generate large maps. RNG uses some hand-rolled bit ops that are probably to blame. Using LuaJIT bit ops when available and falling back to hand-rolled ones will speed things up a lot.
In rot.js, an implementation of Alea is used as the sole RNG. Alea is interesting because it doesn't seem to need bitwise operators at all.*
I've ported the original Alea implementation to Lua and tested in Love against rotLove's Twister; on my machine Alea is about 500 times faster with jit on and 100 times faster with jit off. In other words, with jit on, Alea can generate in an eighth of a second what would take the current Twister a full minute.
To be fair, I tested again with LuaJIT's bit ops patched into Twister, and it's much faster, but still 10x slower than Alea.
*The author uses
>>>0
and|0
in some places, but the only apparent effect is flooring; the truncating to 32 bits doesn't appear to affect the outcome (tested millions of numbers with a handful of seeds, Lua port withmath.floor
in place of>>>0
and|0
gave same results as original JS).