1 import java
.util
.ArrayList
;
2 import java
.util
.LinkedList
;
3 import java
.util
.concurrent
.TimeUnit
;
9 * @param String[] args main() function arguments array
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
>());
15 for (int i
= 0; i
< 1000000; i
++) {
20 long startTime
= System
.nanoTime();
21 //for (int i = 0; i < 100000; i++) {
22 // array.addMiddleIter(i);
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");
30 startTime
= System
.nanoTime();
31 //for (int i = 0; i < 100000; i++) {
32 // list.addMiddleIter(i);
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
));