Advertisement
Guest User

Untitled

a guest
Oct 23rd, 2019
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.29 KB | None | 0 0
  1. import java.util.*;
  2.  
  3. //class to calculate runtime in millisec
  4.  
  5. public class timeCount {
  6.  
  7. public static void main(String[] args) {
  8.  
  9. //to take input array size
  10.  
  11. Scanner s=new Scanner(System.in);
  12.  
  13. System.out.println("Input array size");
  14.  
  15. int n=s.nextInt();
  16.  
  17.  
  18.  
  19. //store the total running time
  20.  
  21. long running_time=0;
  22.  
  23. System.out.println("Number of Items to sort");
  24.  
  25. //to take number of random arrays
  26.  
  27. int num=s.nextInt();
  28.  
  29. //generate num number of random arrays
  30.  
  31. for(int i=0;i<num;i++){
  32.  
  33. int[] arr=sort.generateRandomArr(n);
  34.  
  35. //record the start time
  36.  
  37. long start_time=System.currentTimeMillis();
  38.  
  39. //sort using bubble sort
  40.  
  41. sort.bubble_sort(arr, n);
  42.  
  43. //record the end time
  44.  
  45. long end_time=System.currentTimeMillis();
  46.  
  47. //add the time taken to total running time
  48.  
  49. running_time=running_time+(end_time-start_time);
  50.  
  51. }
  52.  
  53. System.out.println("The number of items sorted:"+num);
  54.  
  55. //average running time for each array
  56.  
  57. double avg_time=(double)running_time/num;
  58.  
  59. System.out.println("Average Running Time:"+avg_time);
  60.  
  61. }
  62.  
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement