/* * Main.java * * Created on January 28, 2007, 3:09 PM * * To change this template, choose Tools | Template Manager * and open the template in the editor. */ package estructuras; import java.util.LinkedList; import java.util.Vector; /** * * @author Magus */ public class Main { /** Creates a new instance of Main */ public Main() { } /** * @param args the command line arguments */ public static void main(String[] args) { int arr[] = null; LinkedList list = null; Vector vector = null; long start = 0; long end = 0; double time = 0; final int SIZE = 65535; System.out.println("------------------------"); System.out.println("Escribir a la estructura"); System.out.println("------------------------"); start = System.nanoTime(); arr = new int[SIZE]; for (int i = 0; i < SIZE; i++) { arr[i] = (int) (Math.random() * Integer.MAX_VALUE); } end = System.nanoTime(); time = (end - start) / 1000000; System.out.println("Utilizando un arreglo: " + time + " milisegundos"); start = System.nanoTime(); list = new LinkedList(); for (int i = 0; i < SIZE; i++) { list.add((int) (Math.random() * Integer.MAX_VALUE)); } end = System.nanoTime(); time = (end - start) / 1000000; System.out.println("Utilizando add() con LinkedList: " + time + " milisegundos"); start = System.nanoTime(); list = new LinkedList(); for (int i = 0; i < SIZE; i++) { list.addFirst((int) (Math.random() * Integer.MAX_VALUE)); } end = System.nanoTime(); time = (end - start) / 1000000; System.out.println("Utilizando addFirst() con LinkedList: " + time + " milisegundos"); start = System.nanoTime(); vector = new Vector(); for (int i = 0; i < SIZE; i++) { vector.add((int) (Math.random() * Integer.MAX_VALUE)); } end = System.nanoTime(); time = (end - start) / 1000000; System.out.println("Utilizando add() con Vector: " + time + " milisegundos"); start = System.nanoTime(); vector = new Vector(); for (int i = 0; i < SIZE; i++) { vector.insertElementAt((int) (Math.random() * Integer.MAX_VALUE), 0); } end = System.nanoTime(); time = (end - start) / 1000000; System.out.println("Utilizando insertElementAt() con Vector en index 0: " + time + " milisegundos"); System.out.println("------------------------"); System.out.println(" Leer de la estructura"); System.out.println("------------------------"); start = System.nanoTime(); arr = new int[SIZE]; for (int i = 0; i < SIZE; i++) { int x = arr[i]; } end = System.nanoTime(); time = (end - start) / 1000000; System.out.println("Utilizando un arreglo: " + time + " milisegundos"); start = System.nanoTime(); for (int i = 0; i < SIZE; i++) { int x = list.get(i); } end = System.nanoTime(); time = (end - start) / 1000000; System.out.println("Utilizando get() con LinkedList: " + time + " milisegundos"); start = System.nanoTime(); for (int i = 0; i < SIZE; i++) { int x = (Integer) vector.get(i); } end = System.nanoTime(); time = (end - start) / 1000000; System.out.println("Utilizando get() con Vector: " + time + " milisegundos"); } }