Guest User

TestJava.java

a guest
Dec 1st, 2018
205
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.38 KB | None | 0 0
  1. //package javaclient.net;
  2. public class TestJava {
  3.     public TestJava child1;
  4.     public TestJava child2;
  5.     public TestJava child3;
  6.  
  7.     public static void main(String[] args) {
  8.         if (args.length<2) {
  9.             System.out.println("TestJava <depth> <reps>");
  10.             return;
  11.         }
  12.         int depth=Integer.parseInt(args[0]);
  13.         int reps=Integer.parseInt(args[1]);
  14.         System.out.println("TestJava started depth="+depth+" reps="+reps);
  15.         float min_time=Long.MAX_VALUE;
  16.         float max_time=Long.MIN_VALUE;
  17.         float avg_time=0;
  18.         int count=0;
  19.         for(int rep=0; rep<reps; rep++) {
  20.             long start = System.nanoTime();
  21.  
  22.             TestJava t=new TestJava(depth);
  23.             count = t.Count();
  24.  
  25.             float elapse = System.nanoTime() - start;
  26.             elapse /= 1000000000;
  27.             //System.out.println(String.format("ELAPSE=%f",elapse));
  28.             if (min_time>elapse) min_time=elapse;
  29.             if (max_time<elapse) max_time=elapse;
  30.             avg_time += elapse;
  31.            
  32.         }
  33.         avg_time /= reps;
  34.         System.out.println(String.format("TestJava count=%d min=%f max=%f avg=%f",count,min_time,max_time,avg_time));
  35.     }
  36.  
  37.     public TestJava(int depth) {
  38.         if (depth>0) {
  39.             depth-=1;
  40.             child1=new TestJava(depth);
  41.             child2=new TestJava(depth);
  42.             child3=new TestJava(depth);
  43.         }
  44.     }
  45.     public int Count() {
  46.         int count=1;
  47.         if (child1!=null) count+=child1.Count();
  48.         if (child2!=null) count+=child2.Count();
  49.         if (child3!=null) count+=child3.Count();
  50.         return count;
  51.     }
  52. }
Advertisement
Add Comment
Please, Sign In to add comment