Thread: [Bprocessor-commit] test/src/net/sourceforge/bprocessor/test NormalsBenchmark.java, NONE, 1.1 Surfa
Status: Pre-Alpha
Brought to you by:
henryml
|
From: Michael L. <he...@us...> - 2007-01-25 10:21:05
|
Update of /cvsroot/bprocessor/test/src/net/sourceforge/bprocessor/test In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv11966/src/net/sourceforge/bprocessor/test Modified Files: SurfaceNormal.java Added Files: NormalsBenchmark.java Log Message: Hit-detection improved Index: SurfaceNormal.java =================================================================== RCS file: /cvsroot/bprocessor/test/src/net/sourceforge/bprocessor/test/SurfaceNormal.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** SurfaceNormal.java 8 Dec 2006 10:55:20 -0000 1.1 --- SurfaceNormal.java 25 Jan 2007 10:21:04 -0000 1.2 *************** *** 47,51 **** while (iter.hasNext()) { Surface current = (Surface) iter.next(); ! Vertex normal = current.normal(); System.out.println(current.getName() + " normal: " + normal); } --- 47,51 ---- while (iter.hasNext()) { Surface current = (Surface) iter.next(); ! Vertex normal = current.normal0(); System.out.println(current.getName() + " normal: " + normal); } --- NEW FILE: NormalsBenchmark.java --- //--------------------------------------------------------------------------------- // $Id: NormalsBenchmark.java,v 1.1 2007/01/25 10:21:04 henryml Exp $ // // Copyright (c) 2005 The BProcessor Team (http://bprocessor.sourceforge.net) // Released under the Lesser GNU Public License v2.1 //--------------------------------------------------------------------------------- package net.sourceforge.bprocessor.test; import java.io.File; import java.util.Collection; import java.util.Iterator; import java.util.LinkedList; import java.util.List; import net.sourceforge.bprocessor.model.CoordinateSystem; import net.sourceforge.bprocessor.model.Entity; import net.sourceforge.bprocessor.model.Persistence; import net.sourceforge.bprocessor.model.Project; import net.sourceforge.bprocessor.model.Space; import net.sourceforge.bprocessor.model.Surface; import net.sourceforge.bprocessor.model.Vertex; /** * */ public class NormalsBenchmark { private static int limit = 2000; private static class Benchmark { public void benchmark() { } public String name() { return this.getClass().getName(); } public void run() { System.out.println("running " + name()); long before = System.currentTimeMillis(); long after = before; int iterations = 0; while ((after - before) < limit) { benchmark(); iterations++; after = System.currentTimeMillis(); } double delta = (after - before); double ellapsed = delta / (double) iterations; long value = (long) (1000 * ellapsed); ellapsed = (double) value / 1000.0; System.out.println(" ellapsed " + ellapsed + "ms"); } } private static class Empty extends Benchmark { private Space space; public Empty(Space space) { this.space = space; } public void benchmark() { Collection surfaces = space.getSurfaces(); Iterator iter = surfaces.iterator(); int count = 0; while (iter.hasNext()) { Surface current = (Surface) iter.next(); count++; } } } private static class Count extends Benchmark { private Space space; public Count(Space space) { this.space = space; } public void benchmark() { Collection surfaces = space.getSurfaces(); Surface[] array = (Surface[]) surfaces.toArray(new Surface[0]); int count = 0; while (count < array.length) { Surface current = array[count]; count++; } } } private static class Compute extends Benchmark { private Space space; private Surface[] array; public Compute(Space space) { this.space = space; Collection surfaces = space.getSurfaces(); array = (Surface[]) surfaces.toArray(new Surface[0]); } public void benchmark() { int count = 0; while (count < array.length) { Surface current = array[count]; Vertex normal = current.normal0(); count++; } } } private static class Direction extends Benchmark { private Space space; private Surface[] array; private CoordinateSystem system; public Direction(Space space) { this.space = space; Collection surfaces = space.getSurfaces(); array = (Surface[]) surfaces.toArray(new Surface[0]); system = Project.getInstance().getActiveCoordinateSystem(); } public void benchmark() { int count = 0; while (count < array.length) { Surface current = array[count]; int direction = current.direction(system); count++; } } } private static class ToArray extends Benchmark { private Space space; public ToArray(Space space) { this.space = space; } public void benchmark() { Collection surfaces = space.getSurfaces(); Surface[] array = (Surface[]) surfaces.toArray(new Surface[0]); } } private static class LLToArray extends Benchmark { private Space space; private LinkedList list; public LLToArray(Space space) { this.space = space; Collection surfaces = space.getSurfaces(); list = new LinkedList(surfaces); } public void benchmark() { Surface[] array = (Surface[]) list.toArray(new Surface[0]); } } private static class Normals extends Benchmark { private Space space; public Normals(Space space) { this.space = space; } public void benchmark() { Collection surfaces = space.getSurfaces(); Iterator iter = surfaces.iterator(); while (iter.hasNext()) { Surface current = (Surface) iter.next(); Vertex normal = current.normal(); } } } /** * @param args args */ public static void main(String[] args) { File input = new File(args[0]); try { Persistence.load(input); Benchmark bench = new Normals(Project.getInstance().world()); bench.run(); bench = new Empty(Project.getInstance().world()); bench.run(); bench = new Count(Project.getInstance().world()); bench.run(); bench = new ToArray(Project.getInstance().world()); bench.run(); bench = new LLToArray(Project.getInstance().world()); bench.run(); bench = new Compute(Project.getInstance().world()); bench.run(); bench = new Direction(Project.getInstance().world()); bench.run(); } catch (Exception e) { e.printStackTrace(); } } /** * Prints the normals of the surfaces * @param surfaces collection of Surface whose normals are to be printed */ private static void printNormals(Collection surfaces) { List sorted = new LinkedList(surfaces); Entity.sort(sorted); Iterator iter = sorted.iterator(); while (iter.hasNext()) { Surface current = (Surface) iter.next(); Vertex normal = current.normal(); System.out.println(current.getName() + " normal: " + normal); } } } |