Replace Math with FastMath for improved performance.

FastMath is a drop in replacement for the native Java math class with improved performance and fall backs to the native Java math class if necessary.

https://commons.apache.org/proper/commons-math/javadocs/api-3.3/org/apache/commons/math3/util/FastMath.html

This requires further testing and might cause chunk borders due the FastMath giving slightly different results than the native Java math class.

I also added .idea/Terra.iml to the .gitignore
This commit is contained in:
Bud Gidiere
2020-11-18 17:23:09 -06:00
parent 19162a1924
commit 0a77487399
21 changed files with 73 additions and 52 deletions

View File

@@ -26,8 +26,8 @@ class DistributionTest {
long l = System.nanoTime();
for(int i = 0; i < 1000000; i++) {
double n = noise.getNoise(0, i);
max = Math.max(max, n);
min = Math.min(min, n);
max = FastMath.max(max, n);
min = FastMath.min(min, n);
numbers[normalize(n, attempts)]++;
}
long l2 = System.nanoTime() - l;
@@ -36,8 +36,8 @@ class DistributionTest {
l = System.nanoTime();
for(int i = 0; i < 1000000; i++) {
double n = noise.getNoise(0, i);
max = Math.max(max, n);
min = Math.min(min, n);
max = FastMath.max(max, n);
min = FastMath.min(min, n);
}
l2 = System.nanoTime() - l;
System.out.println("Took " + (double) l2 / 1000000 + "ms (" + ((double) l2 / 1000000) + "ns per.");
@@ -67,8 +67,8 @@ class DistributionTest {
end = mid;
}
}
double left = Math.abs(normalMap[start] - d);
double right = Math.abs(normalMap[end] - d);
double left = FastMath.abs(normalMap[start] - d);
double right = FastMath.abs(normalMap[end] - d);
if (left <= right) {
return start * (num) / (normalMap.length);
}
@@ -76,7 +76,7 @@ class DistributionTest {
}
public static int normal(double d, int max) {
double ranged = Math.max(0, Math.min((d + 1) / 2D, 1));
double ranged = FastMath.max(0, FastMath.min((d + 1) / 2D, 1));
return (int) (ranged * max);
}
}

View File

@@ -100,8 +100,8 @@ class LookupGenerator {
public static int normalize(double i, int n) {
i *= 1.42; // Magic simplex value (sqrt(2) plus a little)
i = Math.min(Math.max(i, -1), 1);
return Math.min((int) Math.floor((i + 1) * ((double) n / 2)), n - 1);
i = FastMath.min(FastMath.max(i, -1), 1);
return FastMath.min((int) FastMath.floor((i + 1) * ((double) n / 2)), n - 1);
}
private static class Worker extends Thread {