Advertisement
andresdagu

org.pc.sesion12 PrincipalBusqueda

Apr 16th, 2022
1,275
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.53 KB | None | 0 0
  1. package org.pc.sesion12;
  2.  
  3. public class PrincipalBusqueda {
  4.  
  5.     public static void main(String[] args) {
  6.        
  7.         System.out.println("N\tLineal(ms)\tBin.Iter(ms)\tBin.Rec(ms)");
  8.        
  9.         int p = 10;
  10.         int q = 1;
  11.        
  12.         int n = 1000;
  13.         int k = 998;
  14.        
  15.         while (q <= p) {
  16.        
  17.             Busqueda busqueda = new Busqueda(n);
  18.             int[] datos = new int[n];
  19.             int i = 0;
  20.             while (i < n) {
  21.  
  22.                 datos[i] = i;
  23.                 i++;
  24.  
  25.             }
  26.             busqueda.setDatos(datos);
  27.             busqueda.setNumBuscado(k);
  28.             long t0 = System.nanoTime();
  29.             SolucinesBusqueda.busquedaLineal(busqueda);
  30.             long t1 = System.nanoTime();
  31.            
  32.             busqueda = new Busqueda(n);
  33.             datos = new int[n];
  34.             i = 0;
  35.             while (i < (n)) {
  36.  
  37.                 datos[i] = i;
  38.                 i++;
  39.  
  40.             }
  41.             busqueda.setDatos(datos);
  42.             busqueda.setNumBuscado(k);
  43.             long t2 = System.nanoTime();
  44.             SolucinesBusqueda.busquedaBinariaIter(busqueda);
  45.             long t3 = System.nanoTime();
  46.            
  47.             busqueda = new Busqueda(n);
  48.             datos = new int[n];
  49.             i = 0;
  50.             while (i < (n)) {
  51.  
  52.                 datos[i] = i;
  53.                 i++;
  54.  
  55.             }
  56.             busqueda.setDatos(datos);
  57.             busqueda.setNumBuscado(k);
  58.             long t4 = System.nanoTime();
  59.             SolucinesBusqueda.busquedaBinariaIter(busqueda);
  60.             long t5 = System.nanoTime();
  61.            
  62.             System.out.println(n + "\t" + (t1 - t0) + "\t\t" + (t3 - t2) + "\t\t" + (t5 - t4)); //nanoseconds
  63.            
  64. //          System.out.println(n + "\t" + ((int) (t1 - t0) / 1000000) + "\t\t" + ((int) (t3 - t2) / 1000000) + "\t\t" + ((int) (t5 - t4) / 1000000)); //miliseconds
  65.            
  66.             q++;
  67.             n += 1000;
  68.             k += 1000;
  69.         }
  70.        
  71.        
  72.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement