Advertisement
Guest User

TestJava.java

a guest
May 10th, 2019
222
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.02 KB | None | 0 0
  1. public class TestJava {
  2.     public TestJava child1;
  3.     public TestJava child2;
  4.     public TestJava child3;
  5.  
  6.     public static void main(String[] args) {
  7.         if (args.length<3) {
  8.             System.out.println("TestJava <depth> <reps> <gc>");
  9.             return;
  10.         }
  11.         int depth=Integer.parseInt(args[0]);
  12.         int reps=Integer.parseInt(args[1]);
  13.         int gc=Integer.parseInt(args[2]);
  14.         System.out.println("TestJava started depth="+depth+" reps="+reps+" gc="+gc);
  15.         int count=0;
  16.         for(int rep=0; rep<reps; rep++) {
  17.             TestJava t=new TestJava(depth);
  18.             count = t.Count();
  19.             t = null;
  20.             if (gc>0) {
  21.                 System.gc();
  22.             }
  23.  
  24.         }
  25.         System.out.println(String.format("TestJava count=%d",count));
  26.     }
  27.  
  28.     public TestJava(int depth) {
  29.         if (depth>0) {
  30.             depth-=1;
  31.             child1=new TestJava(depth);
  32.             child2=new TestJava(depth);
  33.             child3=new TestJava(depth);
  34.         }
  35.     }
  36.     public int Count() {
  37.         int count=1;
  38.         if (child1!=null) count+=child1.Count();
  39.         if (child2!=null) count+=child2.Count();
  40.         if (child3!=null) count+=child3.Count();
  41.         return count;
  42.     }
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement