Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package hey;
- import java.util.Random;
- public class Loop1 {
- public static void loop1(int n){
- /* O(n logn) Algorithm */
- Random rn = new Random();
- @SuppressWarnings("unused")
- int cont=0;
- for (int i=1; i<=n; i++)
- for (int k=1; k<=n; k++)
- for (int l=1; l<=n; l++)
- for (int j=1; j<=n; j*=2)
- cont += rn.nextInt();
- }
- public static void main(String arg[]){
- long t1, t2;
- int nTimes = Integer.parseInt(arg[0]);
- for (int n=1; n<=100000; n*=2){
- t1 = System.currentTimeMillis ();
- for (int repetitions=1; repetitions<=nTimes;repetitions++) {
- loop1(n);
- }
- t2 = System.currentTimeMillis ();
- System.out.println("n="+n+ "**TIME="+(t2-t1)+"**nTimes="+nTimes);
- } //for
- }//main
- } //class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement