Small code cleanup.
[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();
54c717d4
JB
21 // for (int i = 0; i < 100000; i++) {
22 // array.addIter(array.size() / 2, i);
23 // }
24 array.addNelements(array.size() / 2, 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();
54c717d4
JB
31 // for (int i = 0; i < 100000; i++) {
32 // list.addIter(list.size() / 2, i);
33 // }
34 list.addNelements(list.size() / 2, 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}