jam/RunningTime

From ggc

Jump to: navigation, search

01 package jam;
02 
03 import wiki.Wiki;
04 /**
05  * All about my application here.
06  @author Jam Jenkins
07  */
08 public class RunningTime
09 {
10   public static void doSomething1() throws Exception
11   {
12     String dummy="";
13     synchronized(dummy)
14     {
15       dummy.wait(10);
16     }
17   }
18 
19   public static void doSomething2() throws Exception
20   {
21     String dummy="";
22     synchronized(dummy)
23     {
24       dummy.wait(50);
25     }
26   }
27 
28   public static void doSomething3() throws Exception
29   {
30     String dummy="";
31     synchronized(dummy)
32     {
33       dummy.wait(10);
34     }
35   }
36 
37   public static void main(String[] argsthrows Exception
38   {
39     int timesExecuted=0;
40     int outerExecuted=0;
41     int a=10;
42     int b=8;
43     int c=9;
44     long startTime=System.currentTimeMillis();
45     for(int i=0; i<a; i++)
46     {
47       outerExecuted++;
48       for(int j=0; j<b; j++)
49       {
50         doSomething1();
51         timesExecuted++;
52         for(int k=0; k<c; k++)
53         {
54           doSomething3();
55         }
56       }
57       doSomething2();
58     }
59     long endTime=System.currentTimeMillis();
60     Wiki.out.println("Outer executed "+outerExecuted+" times.");
61     Wiki.out.println("Inner executed "+timesExecuted+" times.");
62     Wiki.out.println("Execution took "+(endTime-startTime)/1000.0+" seconds.");
63   }
64 }


Download/View jam/RunningTime.java





Views
Personal tools
Add to 
del.icio.usAdd to 
diggAdd to 
FacebookAdd to 
favoritesAdd to 
GoogleAdd to 
MySpaceAdd to 
PrintAdd to 
SlashdotAdd to 
StumbleUponAdd to 
Twitter