* Better TempVars benchmark

git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@7752 75d07b2b-3a1a-0410-a2c5-0572b91ccdca
3.0
sha..rd 14 years ago
parent 8523bcb46c
commit 09137fef25
  1. 100
      engine/src/test/jme3test/app/TestTempVars.java

@ -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
vars.vect1.addLocal(vars.vect2);
//release the vars
vars.release();
//Perf tests
//100 million calls // sumCompute.set(0, 0, 0);
d = new Date(); // long nanos = System.nanoTime();
for (int i = 0; i < 100000000; i++) { // 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);
sumCompute.set(0, 0, 0);
nanos = System.nanoTime();
for (int i = 0; i < ITERATIONS; 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);
//recursive Method sumCompute.set(0, 0, 0);
d = new Date(); nanos = System.nanoTime();
recursiveMethod(); for (int i = 0; i < ITERATIONS; i++) {
d2 = new Date(); methodThatUsesAllocation();
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("100 million allocation calls: " + milliseconds + " ms");
System.out.println(sumCompute);
nanos = System.nanoTime();
for (int i = 0; i < 10; i++){
System.gc();
} }
static int recurse = 0; milliseconds = (System.nanoTime() - nanos) / NANOS_TO_MS;
public static void recursiveMethod(){ System.out.println("cleanup time after allocation calls: " + milliseconds + " ms");
TempVars vars = TempVars.get();
vars.vect1.set(123, 999, -55);
recurse++;
if(recurse<5){
recursiveMethod();
} }
vars.release(); public static void methodThatUsesAllocation(){
Vector3f vector = new Vector3f();
vector.set(0.1f, 0.2f, 0.3f);
sumCompute.addLocal(vector);
} }
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();
} }
} }

Loading…
Cancel
Save