intro/ProfilingSearchAndSort

From ggc

Jump to: navigation, search

01 package intro;
02 import java.util.*;
03 import wiki.Wiki;
04 
05 /**
06  * All about my application.
07  @author My Name Here
08  */
09 public class ProfilingSearchAndSort
10 {
11   public static void main(String[] args)
12   {
13     SortingAlgorithms sorter=new SortingAlgorithms();
14     int[] numbers=new int[64000];
15     int timesToRun=1000000;
16     for(int i=0; i<numbers.length; i++)
17     {
18       //fills with random numbers
19       numbers[i]=(int)(Math.random()*10000);
20     }
21     Arrays.sort(numbers);
22     long start=System.currentTimeMillis();
23     for(int replications=0; replications<timesToRun; replications++)
24     {
25       int target=(int)(Math.random()*10000);
26       Arrays.binarySearch(numbers, target);
27       /*for(int i=0; i<numbers.length; i++)
28     {
29         if(numbers[i]==target)
30         {
31           //do nothing
32           break;
33         }
34     }*/
35     }
36     long end=System.currentTimeMillis();
37     double seconds=(end-start)/1000.0/timesToRun;
38     Wiki.out.println("Filling the array took "+seconds+" seconds.");
39   }
40 }


Download/View intro/ProfilingSearchAndSort.java





Views
Personal tools
Add to 
del.icio.usAdd to 
diggAdd to 
FacebookAdd to 
favoritesAdd to 
GoogleAdd to 
MySpaceAdd to 
PrintAdd to 
SlashdotAdd to 
StumbleUponAdd to 
Twitter