import java.util.Random; import java.util.Arrays; /* In Order: Naive Shape --------------------- centre of mass: (0.0012315639934572676, 3.4690922854647803E-4, -4.4056706657348566E-4) min: 111049000 med: 124352000 95%: 185673000 max: 235142000 In Order: Packed Shape ---------------------- centre of mass: (0.0012315639934572676, 3.4690922854647803E-4, -4.4056706657348566E-4) min: 96216000 med: 106892000 95%: 146708000 max: 209965000 In Order: Dominik Shape ----------------------- centre of mass: (0.0012315639934572676, 3.4690922854647803E-4, -4.4056706657348566E-4) min: 131850000 med: 149605000 95%: 206983000 max: 643793000 Shuffled: Naive Shape --------------------- centre of mass: (9.837182530244893E-4, 1.713023779409509E-4, -2.636834023628827E-4) min: 136890000 med: 151244000 95%: 268689000 max: 508154000 Shuffled: Packed Shape ---------------------- centre of mass: (9.837182530244893E-4, 1.713023779409509E-4, -2.636834023628827E-4) min: 96196000 med: 108204000 95%: 160004000 max: 167001000 Shuffled: Dominik Shape ----------------------- centre of mass: (9.837182530244893E-4, 1.713023779409509E-4, -2.636834023628827E-4) min: 131995000 med: 148993000 95%: 201279000 max: 585317000 */ public class PointBench { public static void main(String... args) throws InterruptedException { final int N = 1000000; final boolean SHUFFLE = false; Shape shape = makeShape(N, SHUFFLE); System.out.println("centre of mass: " + shape.getCentreOfMass()); long[] times = new long[101]; for (int i = 0; i < 30; ++i) benchGetCentreOfMass(shape); System.gc(); Thread.sleep(100); for (int i = 0; i < times.length; ++i) { times[i] = benchGetCentreOfMass(shape); } Arrays.sort(times); System.out.println("min: " + times[0]); System.out.println("med: " + times[times.length / 2]); System.out.println("95%: " + times[(int)(times.length * 0.95f)]); System.out.println("max: " + times[times.length - 1]); } private static Shape makeShape(int n, boolean shuffle) { Random rnd = new Random(8490490238402189L); int[] indices = new int[n]; for (int i = 0; i < n; ++i) indices[i] = i; if (shuffle) { for (int i = 0; i < (n - 1); ++i) { int j = i + rnd.nextInt(n - i); int t = indices[i]; indices[i] = indices[j]; indices[j] = t; } } Shape shape = new Shape(n); for (int i = 0; i < n; ++i) { shape.setPoint(indices[i], new Point(rnd.nextGaussian(), rnd.nextGaussian(), rnd.nextGaussian())); } return shape; } private static long benchGetCentreOfMass(Shape shape) { long t0 = System.nanoTime(); shape.getCentreOfMass(); long t1 = System.nanoTime(); return t1 - t0; } }