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);
- float min_time=Long.MAX_VALUE;
- float max_time=Long.MIN_VALUE;
- float avg_time=0;
- int count=0;
- for(int rep=0; rep<reps; rep++) {
- long start = System.nanoTime();
- TestJava t=new TestJava(depth);
- count = t.Count();
- float elapse = System.nanoTime() - start;
- elapse /= 1000000000;
- //System.out.println(String.format("ELAPSE=%f",elapse));
- if (min_time>elapse) min_time=elapse;
- if (max_time<elapse) max_time=elapse;
- avg_time += elapse;
- }
- avg_time /= reps;
- System.out.println(String.format("TestJava count=%d min=%f max=%f avg=%f",count,min_time,max_time,avg_time));
- }
- 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