From 280c16cf788635d9487587ff4c1e8df3e74af4d7 Mon Sep 17 00:00:00 2001 From: Nick Klose Date: Fri, 13 Dec 2013 12:15:49 +0100 Subject: [PATCH] Finished performance test of chooser --- .../MarkPassingCalculatorPerformanceTest.java | 110 ++++++++---------- 1 file changed, 49 insertions(+), 61 deletions(-) diff --git a/java/com.sap.sailing.domain.test/src/com/sap/sailing/domain/test/markpassing/MarkPassingCalculatorPerformanceTest.java b/java/com.sap.sailing.domain.test/src/com/sap/sailing/domain/test/markpassing/MarkPassingCalculatorPerformanceTest.java index 9c3f2863cbf..6f0a51c5bcd 100755 --- a/java/com.sap.sailing.domain.test/src/com/sap/sailing/domain/test/markpassing/MarkPassingCalculatorPerformanceTest.java +++ b/java/com.sap.sailing.domain.test/src/com/sap/sailing/domain/test/markpassing/MarkPassingCalculatorPerformanceTest.java @@ -3,9 +3,9 @@ package com.sap.sailing.domain.test.markpassing; import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import java.util.Random; import java.util.UUID; -import org.junit.Before; import org.junit.Test; import com.sap.sailing.domain.base.Competitor; @@ -45,8 +45,10 @@ public class MarkPassingCalculatorPerformanceTest { private Mark m2 = new MarkImpl("white 1"); private Mark m3 = new MarkImpl("white 2"); + private List waypoints = new ArrayList<>(); private DynamicTrackedRace trackedRace; - private long time; + private double time; + Random rnd = new Random(); public MarkPassingCalculatorPerformanceTest() { ControlPointWithTwoMarks cp = new ControlPointWithTwoMarksImpl(m2, m3, "cp"); @@ -70,74 +72,60 @@ public class MarkPassingCalculatorPerformanceTest { System.currentTimeMillis()))); trackedRace.recordFix(m3, new GPSFixImpl(new DegreePosition(37.887936, -122.268841), new MillisecondsTimePoint( System.currentTimeMillis()))); - } - - @Before - public void clearMarkPasses() { - - } - - @Test - public void testTimeOfAddingManyCandidatesToChooser() { - int numberOfCandidates = 500; - List waypoints = new ArrayList<>(); for (Waypoint w : trackedRace.getRace().getCourse().getWaypoints()) { waypoints.add(w); } + } + + + @Test + public void Cans500(){ + testAddingCandidatesToChooser(500); + } + @Test + public void Cans1000(){ + testAddingCandidatesToChooser(1000); + } + @Test + public void Cans2000(){ + testAddingCandidatesToChooser(2000); + } + + + private void testAddingCandidatesToChooser(int numberOfCandidates) { ArrayList newCans = new ArrayList<>(); - int id = 0; for (int i = 0; i < numberOfCandidates; i++) { - newCans.add(new Candidate(id + 1, new MillisecondsTimePoint( - (long) (System.currentTimeMillis() - 300000 + (Math.random() * (7800000)))), 0.5 + 0.5 * Math - .random(), waypoints.get(id))); - if (id == 4) { - id = 0; - } else { - id++; - } + newCans.add(randomCan()); } time = System.currentTimeMillis(); - new CandidateChooser(trackedRace).calculateMarkPassDeltas(bob, new Pair, List>( + CandidateChooser c = new CandidateChooser(trackedRace); + c.calculateMarkPassDeltas(bob, new Pair, List>( newCans, new ArrayList())); - System.out.println(System.currentTimeMillis() - time); + System.out.println(System.currentTimeMillis() - time + " ms to add " + numberOfCandidates + + " Candidates to Chooser."); + + ArrayList times = new ArrayList<>(); + Candidate old = newCans.get(0); + for (int i = 0; i < 100; i++) { + Candidate ne; + ne = randomCan(); + time = System.currentTimeMillis(); + c.calculateMarkPassDeltas(bob, + new Pair, List>(Arrays.asList(ne), Arrays.asList(old))); + times.add(System.currentTimeMillis() - time); + old = ne; + } + double total = 0; + for (double d : times) { + total = total + d; + } + System.out.println("On average " + total / times.size() + " ms to add and remove one Candidate."); } - @Test - public void testTimeOfAddingOneCandidateToChooser() { - int numberOfCandidatesInChooser = 500; - - - - List waypoints = new ArrayList<>(); - for (Waypoint w : trackedRace.getRace().getCourse().getWaypoints()) { - waypoints.add(w); - } - ArrayList newCans = new ArrayList<>(); - int id = 0; - for (int i = 0; i < numberOfCandidatesInChooser; i++) { - newCans.add(new Candidate(id + 1, new MillisecondsTimePoint( - (long) (System.currentTimeMillis() - 300000 + (Math.random() * (7800000)))), 0.5 + 0.5 * Math - .random(), waypoints.get(id))); - if (id == 4) { - id = 0; - } else { - id++; - } - } - - CandidateChooser c = new CandidateChooser(trackedRace); - c.calculateMarkPassDeltas(bob, new Pair, List>(newCans, - new ArrayList())); - while (true) { - newCans.clear(); //Remove old Candidate!! - newCans.add(new Candidate(id + 1, new MillisecondsTimePoint( - (long) (System.currentTimeMillis() - 300000 + (Math.random() * (7800000)))), 0.5 + 0.5 * Math - .random(), waypoints.get(id))); - - time = System.currentTimeMillis(); - c.calculateMarkPassDeltas(bob, new Pair, List>(newCans, - new ArrayList())); - System.out.println(System.currentTimeMillis() - time); - } + private Candidate randomCan() { + int id = rnd.nextInt(5); + return new Candidate(id + 1, new MillisecondsTimePoint( + (long) (System.currentTimeMillis() - 300000 + (Math.random() * (7800000)))), 0.5 + 0.5 * Math.random(), + waypoints.get(id)); } }