exo5: add a SortedMap from the TreeMap.
[Project_POO.git] / exo2 / Main.java
1 import java.util.ArrayList;
2 import java.util.LinkedList;
3 import java.util.concurrent.TimeUnit;
4
5 class Main {
6
7 /**
8 * The main() function
9 * @param String[] args main() function arguments array
10 */
11 public static void main(String[] args) {
12 ListExtension<Integer> array = new ListExtension<Integer>(new ArrayList<Integer>());
13 ListExtension<Integer> list = new ListExtension<Integer>(new LinkedList<Integer>());
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++) {
22 // array.addMiddleIter(i);
23 //}
24 array.addNEMiddle(100000);
25 long stopTime = System.nanoTime();
26 long execTimeArray = stopTime - startTime;
27 //System.out.println("Insert time in the middle of the ArrayList: " + TimeUnit.NANOSECONDS.toSeconds(execTime) + " s");
28 System.out.println("Insert time in the middle of the ArrayList: " + execTimeArray + " ns");
29
30 startTime = System.nanoTime();
31 //for (int i = 0; i < 100000; i++) {
32 // list.addMiddleIter(i);
33 //}
34 list.addNEMiddle(100000);
35 stopTime = System.nanoTime();
36 long execTimeLinked = stopTime - startTime;
37 //System.out.println("Insert time in the middle of the LinkedList: " + TimeUnit.NANOSECONDS.toSeconds(execTime) + " s");
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));
40 }
41 }