Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package alg717254455R.s2;
- import java.util.Random;
- public class Loop5 {
- public static void loop5(int n) {
- /*Quadratic algorithm O(n^4) */
- Random rn = new Random();
- @SuppressWarnings("unused")
- int cont=0;
- for (int i = 0; i < n * n * n; i++) {
- 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++){
- loop5(n);
- }
- t2 = System.currentTimeMillis();
- System.out.println ("n="+n+ "**TIME=" +(t2-t1)+ " ** nTimes=" + nTimes);
- } //for
- } //main
- }
Add Comment
Please, Sign In to add comment