Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //package javaclient.net;
- public class TestJava {
- public TestJava child1;
- public TestJava child2;
- public TestJava child3;
- public static void main(String[] args) {
- if (args.length<2) {
- System.out.println("TestJava <depth> <reps>");
- return;
- }
- int depth=Integer.parseInt(args[0]);
- int reps=Integer.parseInt(args[1]);
- System.out.println("TestJava started depth="+depth+" reps="+reps);
- int count=0;
- for(int rep=0; rep<reps; rep++) {
- //System.gc();
- TestJava t=new TestJava(depth);
- count = t.Count();
- }
- System.gc();
- System.out.println(String.format("TestJava count=%d",count));
- }
- public TestJava(int depth) {
- if (depth>0) {
- depth-=1;
- child1=new TestJava(depth);
- child2=new TestJava(depth);
- child3=new TestJava(depth);
- }
- }
- public int Count() {
- int count=1;
- if (child1!=null) count+=child1.Count();
- if (child2!=null) count+=child2.Count();
- if (child3!=null) count+=child3.Count();
- return count;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement