Advertisement
Guest User

TestJava.java

a guest
Dec 2nd, 2018
205
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.98 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.         int count=0;
  16.         for(int rep=0; rep<reps; rep++) {
  17.  
  18.             //System.gc();
  19.             TestJava t=new TestJava(depth);
  20.             count = t.Count();
  21.  
  22.         }
  23.         System.gc();
  24.         System.out.println(String.format("TestJava count=%d",count));
  25.     }
  26.  
  27.     public TestJava(int depth) {
  28.         if (depth>0) {
  29.             depth-=1;
  30.             child1=new TestJava(depth);
  31.             child2=new TestJava(depth);
  32.             child3=new TestJava(depth);
  33.         }
  34.     }
  35.     public int Count() {
  36.         int count=1;
  37.         if (child1!=null) count+=child1.Count();
  38.         if (child2!=null) count+=child2.Count();
  39.         if (child3!=null) count+=child3.Count();
  40.         return count;
  41.     }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement