|
|
@ -31,80 +31,84 @@ |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
package jme3test.app; |
|
|
|
package jme3test.app; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import com.jme3.math.Vector3f; |
|
|
|
import com.jme3.util.TempVars; |
|
|
|
import com.jme3.util.TempVars; |
|
|
|
import java.util.Date; |
|
|
|
|
|
|
|
import java.util.Iterator; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public class TestTempVars { |
|
|
|
public class TestTempVars { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static final int ITERATIONS = 10000000; |
|
|
|
|
|
|
|
private static final int NANOS_TO_MS = 1000000; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static final Vector3f sumCompute = new Vector3f(); |
|
|
|
|
|
|
|
|
|
|
|
public static void main(String[] args) { |
|
|
|
public static void main(String[] args) { |
|
|
|
|
|
|
|
long milliseconds, nanos; |
|
|
|
|
|
|
|
|
|
|
|
Date d,d2; |
|
|
|
for (int i = 0; i < 4; i++){ |
|
|
|
System.err.println("NOTE: This test simulates a data corruption attempt\n" |
|
|
|
System.gc(); |
|
|
|
+ " in the engine. If assertions are enabled (-ea VM flag), the \n" |
|
|
|
} |
|
|
|
+ "data corruption will be detected and displayed below."); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//get the vars
|
|
|
|
|
|
|
|
TempVars vars = TempVars.get(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// do something with temporary vars
|
|
|
|
// sumCompute.set(0, 0, 0);
|
|
|
|
vars.vect1.addLocal(vars.vect2); |
|
|
|
// long nanos = System.nanoTime();
|
|
|
|
|
|
|
|
// for (int i = 0; i < ITERATIONS; i++) {
|
|
|
|
|
|
|
|
// recursiveMethod(0);
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// long milliseconds = (System.nanoTime() - nanos) / NANOS_TO_MS;
|
|
|
|
|
|
|
|
// System.out.println("100 million TempVars calls with 5 recursions: " + milliseconds + " ms");
|
|
|
|
|
|
|
|
// System.out.println(sumCompute);
|
|
|
|
|
|
|
|
|
|
|
|
//release the vars
|
|
|
|
sumCompute.set(0, 0, 0); |
|
|
|
vars.release(); |
|
|
|
nanos = System.nanoTime(); |
|
|
|
|
|
|
|
for (int i = 0; i < ITERATIONS; i++) { |
|
|
|
//Perf tests
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//100 million calls
|
|
|
|
|
|
|
|
d = new Date(); |
|
|
|
|
|
|
|
for (int i = 0; i < 100000000; i++) { |
|
|
|
|
|
|
|
methodThatUsesTempVars(); |
|
|
|
methodThatUsesTempVars(); |
|
|
|
} |
|
|
|
} |
|
|
|
d2 = new Date(); |
|
|
|
milliseconds = (System.nanoTime() - nanos) / NANOS_TO_MS; |
|
|
|
System.out.println("100 million calls : " +(d2.getTime() - d.getTime())+" ms"); |
|
|
|
System.out.println("100 million TempVars calls: " + milliseconds + " ms"); |
|
|
|
|
|
|
|
System.out.println(sumCompute); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
sumCompute.set(0, 0, 0); |
|
|
|
|
|
|
|
nanos = System.nanoTime(); |
|
|
|
|
|
|
|
for (int i = 0; i < ITERATIONS; i++) { |
|
|
|
|
|
|
|
methodThatUsesAllocation(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
milliseconds = (System.nanoTime() - nanos) / NANOS_TO_MS; |
|
|
|
|
|
|
|
System.out.println("100 million allocation calls: " + milliseconds + " ms"); |
|
|
|
|
|
|
|
System.out.println(sumCompute); |
|
|
|
|
|
|
|
|
|
|
|
//recursive Method
|
|
|
|
nanos = System.nanoTime(); |
|
|
|
d = new Date(); |
|
|
|
for (int i = 0; i < 10; i++){ |
|
|
|
recursiveMethod(); |
|
|
|
System.gc(); |
|
|
|
d2 = new Date(); |
|
|
|
|
|
|
|
System.out.println("100 recursive calls : " +(d2.getTime() - d.getTime())+" ms"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
d = new Date(); |
|
|
|
|
|
|
|
for (int i = 0; i < 1000000; i++) { |
|
|
|
|
|
|
|
methodThatUsesTempVarsWithNoRelease(); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
d2 = new Date(); |
|
|
|
milliseconds = (System.nanoTime() - nanos) / NANOS_TO_MS; |
|
|
|
System.out.println("1 million calls with no release : " +(d2.getTime() - d.getTime())+" ms"); |
|
|
|
System.out.println("cleanup time after allocation calls: " + milliseconds + " ms"); |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
static int recurse = 0; |
|
|
|
|
|
|
|
public static void recursiveMethod(){ |
|
|
|
public static void methodThatUsesAllocation(){ |
|
|
|
TempVars vars = TempVars.get(); |
|
|
|
Vector3f vector = new Vector3f(); |
|
|
|
vars.vect1.set(123, 999, -55); |
|
|
|
vector.set(0.1f, 0.2f, 0.3f); |
|
|
|
recurse++; |
|
|
|
sumCompute.addLocal(vector); |
|
|
|
if(recurse<5){ |
|
|
|
|
|
|
|
recursiveMethod(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
vars.release(); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public static void methodThatUsesTempVars() { |
|
|
|
public static void recursiveMethod(int recurse) { |
|
|
|
TempVars vars = TempVars.get(); |
|
|
|
TempVars vars = TempVars.get(); |
|
|
|
{ |
|
|
|
{ |
|
|
|
vars.vect1.set(123, 999, -55); |
|
|
|
vars.vect1.set(0.1f, 0.2f, 0.3f); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (recurse < 4) { |
|
|
|
|
|
|
|
recursiveMethod(recurse + 1); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
sumCompute.addLocal(vars.vect1); |
|
|
|
} |
|
|
|
} |
|
|
|
vars.release(); |
|
|
|
vars.release(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public static void methodThatUsesTempVarsWithNoRelease() { |
|
|
|
public static void methodThatUsesTempVars() { |
|
|
|
TempVars vars = TempVars.get(); |
|
|
|
TempVars vars = TempVars.get(); |
|
|
|
{ |
|
|
|
{ |
|
|
|
vars.vect1.set(123, 999, -55); |
|
|
|
vars.vect1.set(0.1f, 0.2f, 0.3f); |
|
|
|
|
|
|
|
sumCompute.addLocal(vars.vect1); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
vars.release(); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|