From 09137fef25d77955d5b1e8cb6ac6b18e24b706c3 Mon Sep 17 00:00:00 2001 From: "sha..rd" Date: Sun, 26 Jun 2011 22:45:49 +0000 Subject: [PATCH] * Better TempVars benchmark git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@7752 75d07b2b-3a1a-0410-a2c5-0572b91ccdca --- .../src/test/jme3test/app/TestTempVars.java | 106 +++++++++--------- 1 file changed, 55 insertions(+), 51 deletions(-) diff --git a/engine/src/test/jme3test/app/TestTempVars.java b/engine/src/test/jme3test/app/TestTempVars.java index 3214a7082..710288864 100644 --- a/engine/src/test/jme3test/app/TestTempVars.java +++ b/engine/src/test/jme3test/app/TestTempVars.java @@ -31,80 +31,84 @@ */ package jme3test.app; +import com.jme3.math.Vector3f; import com.jme3.util.TempVars; -import java.util.Date; -import java.util.Iterator; 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) { + long milliseconds, nanos; - Date d,d2; - System.err.println("NOTE: This test simulates a data corruption attempt\n" - + " 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(); + for (int i = 0; i < 4; i++){ + System.gc(); + } - // do something with temporary vars - vars.vect1.addLocal(vars.vect2); +// sumCompute.set(0, 0, 0); +// 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 - vars.release(); - - //Perf tests - - //100 million calls - d = new Date(); - for (int i = 0; i < 100000000; i++) { + sumCompute.set(0, 0, 0); + nanos = System.nanoTime(); + for (int i = 0; i < ITERATIONS; i++) { methodThatUsesTempVars(); } - d2 = new Date(); - System.out.println("100 million calls : " +(d2.getTime() - d.getTime())+" ms"); - + milliseconds = (System.nanoTime() - nanos) / NANOS_TO_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 - d = new Date(); - recursiveMethod(); - 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(); + nanos = System.nanoTime(); + for (int i = 0; i < 10; i++){ + System.gc(); } - d2 = new Date(); - System.out.println("1 million calls with no release : " +(d2.getTime() - d.getTime())+" ms"); - + milliseconds = (System.nanoTime() - nanos) / NANOS_TO_MS; + System.out.println("cleanup time after allocation calls: " + milliseconds + " ms"); } - static int recurse = 0; - public static void recursiveMethod(){ - 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(); { - 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(); } - public static void methodThatUsesTempVarsWithNoRelease() { + public static void methodThatUsesTempVars() { 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(); } }