Open mattdesl opened 1 year ago
You can improve his even more. Instead t * t * t * t * (Grad...)
just use (t *= t, t *= t) * (Grad...)
Also instead:
// 10 ops
const x1 = x0 - i1 + G2;
const y1 = y0 - j1 + G2;
const x2 = x0 - 1.0 + 2.0 * G2;
const y2 = y0 - 1.0 + 2.0 * G2;
you can use:
// 8 ops
const xG = x0 + G2;
const yG = y0 + G2;
const x1 = xG - i1;
const y1 = yG - j1;
const x2 = xG + G2 - 1.0;
const y2 = yG + G2 - 1.0;
I don't think all these improvements will give a strong performance boost, but it's worth checking out nonetheless
I'm working on some optimizations and notice it could be sped up in V8. This is tested with node v19.9.0 and latest Chrome on a MacBook Air M2.
I specifically tested the 2D version but assume the same will hold across all. I've attached the code at the end of this post.
Optimizations:
n * n * n * n
instead ofMath.pow
(note: this is where almost all of the speed-up comes from)0.5 * (Math.sqrt(3.0) - 1.0)
calculationWith 10M iterations: ~1.4s before, ~0.4s after.
Note the exponentiation change introduces a very small loss of precision. For example the noise value might be -0.9466193945512852 instead of -0.9466193945512853 (the precision loss always seems to be below 0.000000000000001).
Benchmark using this PRNG for constancy.
Code changes: