I\'m working on a terrain generation algorithm for a MineCraft-like world. Currently, I\'m using simplex noise based on the implementation in the paper \'Simplex Noise Demys
The thing that stands out initially is that your code is highly polymorphic. You should specialize your floating point type uniformly to Double, so GHC (and LLVM) have a chance of applying more aggressive optimizations.
Note, for those trying to reproduce, this code imports:
import qualified Data.Vector as V
import Data.Bits
import Data.Time.Clock
import System.Random
import System.Random.Shuffle
type Permutation = V.Vector Int
Ok. There's lots of things you can try to improve this code.
Improvements
Data representation
(a,a,a) with unboxed triple T !Double !Double !DoubleData.Array to Data.Array.Unboxed for Permutationsrepa packageCompiler flags
-O2 -fvia-C -optc-O3 -fexcess-precision -optc-march=native (or equivalent with -fllvm)-fspec-constr-count=16More efficient library functions
mod with remV.! indexing with unchecked indexing VU.unsafeIndex (after moving to Data.Vector.UnboxedRuntime settings
-A20M or -HAlso, check your algorithm is identical to the C# one, and you're using the same data structures.