exo2 & 3: Think object and add exo3 code from A to B.
[Project_POO.git] / exo2 / Main.java
CommitLineData
b42baaeb
JB
1import java.util.ArrayList;
2import java.util.LinkedList;
b42baaeb
JB
3import java.util.concurrent.TimeUnit;
4
5class Main {
6
b42baaeb
JB
7 /**
8 * The main() function
9 * @param String[] args main() function arguments array
10 */
11 public static void main(String[] args) {
01bad5b3
JB
12 ListExtension<Integer> array = new ListExtension<Integer>(new ArrayList<Integer>());
13 ListExtension<Integer> list = new ListExtension<Integer>(new LinkedList<Integer>());
b42baaeb
JB
14
15 for (int i = 0; i < 1000000; i++) {
16 array.add(i);
17 list.add(i);
18 }
19
20 long startTime = System.nanoTime();
21 //for (int i = 0; i < 100000; i++) {
01bad5b3 22 // array.addMiddleIter(i);
b42baaeb 23 //}
01bad5b3 24 array.addNEMiddle(100000);
b42baaeb 25 long stopTime = System.nanoTime();
01bad5b3 26 long execTimeArray = stopTime - startTime;
b42baaeb 27 //System.out.println("Insert time in the middle of the ArrayList: " + TimeUnit.NANOSECONDS.toSeconds(execTime) + " s");
01bad5b3 28 System.out.println("Insert time in the middle of the ArrayList: " + execTimeArray + " ns");
b42baaeb
JB
29
30 startTime = System.nanoTime();
31 //for (int i = 0; i < 100000; i++) {
01bad5b3 32 // list.addMiddleIter(i);
b42baaeb 33 //}
01bad5b3 34 list.addNEMiddle(100000);
b42baaeb 35 stopTime = System.nanoTime();
01bad5b3 36 long execTimeLinked = stopTime - startTime;
b42baaeb 37 //System.out.println("Insert time in the middle of the LinkedList: " + TimeUnit.NANOSECONDS.toSeconds(execTime) + " s");
01bad5b3
JB
38 System.out.println("Insert time in the middle of the LinkedList: " + execTimeLinked + " ns");
39 System.out.println("Rapport du temps d'execution ArrayList/LinkedList = " + (execTimeArray / execTimeLinked));
b42baaeb
JB
40 }
41}