Advertisement
claukiller

Untitled

Feb 15th, 2016
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.75 KB | None | 0 0
  1. package hey;
  2.  
  3. import java.util.Random;
  4.  
  5. public class Loop1 {
  6. public static void loop1(int n){
  7. /* O(n logn) Algorithm */
  8. Random rn = new Random();
  9. @SuppressWarnings("unused")
  10. int cont=0;
  11. for (int i=1; i<=n; i++)
  12. for (int k=1; k<=n; k++)
  13. for (int l=1; l<=n; l++)
  14. for (int j=1; j<=n; j*=2)
  15. cont += rn.nextInt();
  16. }
  17.  
  18. public static void main(String arg[]){
  19. long t1, t2;
  20. int nTimes = Integer.parseInt(arg[0]);
  21.  
  22. for (int n=1; n<=100000; n*=2){
  23. t1 = System.currentTimeMillis ();
  24.  
  25. for (int repetitions=1; repetitions<=nTimes;repetitions++) {
  26. loop1(n);
  27. }
  28.  
  29. t2 = System.currentTimeMillis ();
  30. System.out.println("n="+n+ "**TIME="+(t2-t1)+"**nTimes="+nTimes);
  31. } //for
  32.  
  33. }//main
  34. } //class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement