Created
January 31, 2013 05:37
-
-
Save ybonnel/4680556 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package fr.ybonnel.codestory; | |
| import com.google.common.primitives.Longs; | |
| import fr.ybonnel.codestory.path.jajascript.Flight; | |
| import fr.ybonnel.codestory.path.jajascript.JajascriptService; | |
| import org.junit.Ignore; | |
| import org.junit.Test; | |
| import java.util.ArrayList; | |
| import java.util.List; | |
| import java.util.Random; | |
| import java.util.UUID; | |
| import java.util.concurrent.TimeUnit; | |
| /** | |
| * Created with IntelliJ IDEA. | |
| * User: ybonnel | |
| * Date: 31/01/13 | |
| * Time: 06:36 | |
| * To change this template use File | Settings | File Templates. | |
| */ | |
| public class JajascriptPerfTest { | |
| private Random rand = new Random(); | |
| private Flight[] randFilghts(int nbFlights) { | |
| List<Flight> flights = new ArrayList<Flight>(); | |
| for (int i=0; i<nbFlights; i++) { | |
| Flight flight = new Flight(); | |
| flight.setName(UUID.randomUUID().toString()); | |
| flight.setStartTime(rand.nextInt(nbFlights/2)); | |
| flight.setDuration(rand.nextInt(10) + 1); | |
| flight.setPrice(rand.nextInt(100) + 1); | |
| flights.add(flight); | |
| } | |
| return flights.toArray(new Flight[nbFlights]); | |
| } | |
| private void testALevel(int nbFlights) { | |
| int nbOccurToTest = 5; | |
| long totalElapsedTime = 0; | |
| long minElapsedTime = Long.MAX_VALUE; | |
| long maxElapsedTime = 0; | |
| for (int i = 0; i <= nbOccurToTest; i++) { | |
| JajascriptService service; | |
| long startTime; | |
| { | |
| Flight[] flights = randFilghts(nbFlights); | |
| startTime = System.nanoTime(); | |
| service = new JajascriptService(flights); | |
| } | |
| service.calculate(); | |
| long elapsedTime = System.nanoTime() - startTime; | |
| if (i != 0) { | |
| totalElapsedTime += elapsedTime; | |
| minElapsedTime = Longs.min(minElapsedTime, elapsedTime); | |
| maxElapsedTime = Longs.max(maxElapsedTime, elapsedTime); | |
| } | |
| System.out.println("Test " + i + " : " + TimeUnit.NANOSECONDS.toMillis(elapsedTime)); | |
| } | |
| System.out.println("NbFlights " + nbFlights + " :"); | |
| System.out.println("\tMin : " + TimeUnit.NANOSECONDS.toMillis(minElapsedTime)); | |
| System.out.println("\tMax : " + TimeUnit.NANOSECONDS.toMillis(maxElapsedTime)); | |
| System.out.println("\tMoy : " + TimeUnit.NANOSECONDS.toMillis(totalElapsedTime / nbOccurToTest)); | |
| } | |
| @Test | |
| @Ignore | |
| public void testManyLevels() { | |
| testALevel(50000); | |
| testALevel(100000); | |
| testALevel(200000); | |
| testALevel(500000); | |
| testALevel(1000000); | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Test 0 : 225 | |
| Test 1 : 236 | |
| Test 2 : 21 | |
| Test 3 : 17 | |
| Test 4 : 17 | |
| Test 5 : 16 | |
| NbFlights 50000 : | |
| Min : 16 | |
| Max : 236 | |
| Moy : 61 | |
| Test 0 : 40 | |
| Test 1 : 36 | |
| Test 2 : 38 | |
| Test 3 : 36 | |
| Test 4 : 45 | |
| Test 5 : 44 | |
| NbFlights 100000 : | |
| Min : 36 | |
| Max : 45 | |
| Moy : 40 | |
| Test 0 : 86 | |
| Test 1 : 79 | |
| Test 2 : 93 | |
| Test 3 : 90 | |
| Test 4 : 81 | |
| Test 5 : 83 | |
| NbFlights 200000 : | |
| Min : 79 | |
| Max : 93 | |
| Moy : 85 | |
| Test 0 : 258 | |
| Test 1 : 251 | |
| Test 2 : 273 | |
| Test 3 : 261 | |
| Test 4 : 238 | |
| Test 5 : 294 | |
| NbFlights 500000 : | |
| Min : 238 | |
| Max : 294 | |
| Moy : 263 | |
| Test 0 : 688 | |
| Test 1 : 605 | |
| Test 2 : 612 | |
| Test 3 : 574 | |
| Test 4 : 616 | |
| Test 5 : 574 | |
| NbFlights 1000000 : | |
| Min : 574 | |
| Max : 616 | |
| Moy : 596 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment