24 import java.io.PrintWriter;
25 import utils.HrtStopwatch;
26 import utils.HrtProfiler;
30 static protected final PrintWriter out =
new PrintWriter(System.out,
true);
32 static protected final PrintWriter err =
new PrintWriter(System.err,
true);
38 out.print(
"loading libary ...");
41 System.loadLibrary(name);
42 }
catch (UnsatisfiedLinkError e) {
45 path = System.getProperty(
"java.library.path");
46 }
catch (Exception ex) {
47 path =
"<exception caught: " + ex.getMessage() +
">";
49 err.println(
"failed loading library '"
50 + name +
"'; java.library.path='" + path +
"'");
52 }
catch (SecurityException e) {
53 err.println(
"failed loading library '"
54 + name +
"'; caught exception: " + e);
57 out.println(
" [" + name +
"]");
60 static public volatile long dummy;
61 static public void do_something()
63 final long loop = 100000000L;
65 for (i = 0; i < loop; i++)
69 static public void test0()
71 out.println(
"--> HrtStopwatchTest.test0()");
73 out.println(
"marking global time...");
74 int g0 = HrtStopwatch.pushmark();
77 out.println(
"marking global time...");
78 int g1 = HrtStopwatch.pushmark();
81 out.println(
"marking global time...");
82 int g2 = HrtStopwatch.pushmark();
84 assert (HrtStopwatch.top() == 2);
86 out.println(
"amount of times:");
87 double rt0 = HrtStopwatch.rtmicros(g1, g0);
88 double rt1 = HrtStopwatch.rtmicros(g2, g1);
89 double rt2 = HrtStopwatch.rtmicros(g2, g0);
90 out.println(
"[t0..t1] real = " + rt0 +
" us");
91 out.println(
"[t1..t2] real = " + rt1 +
" us");
92 out.println(
"[t0..t2] real = " + rt2 +
" us");
93 double ct0 = HrtStopwatch.ctmicros(g1, g0);
94 double ct1 = HrtStopwatch.ctmicros(g2, g1);
95 double ct2 = HrtStopwatch.ctmicros(g2, g0);
96 out.println(
"[t0..t1] cpu = " + ct0 +
" us");
97 out.println(
"[t1..t2] cpu = " + ct1 +
" us");
98 out.println(
"[t0..t2] cpu = " + ct2 +
" us");
100 out.println(
"popping timemarks");
101 HrtStopwatch.popmark();
102 assert (HrtStopwatch.top() == 1);
103 HrtStopwatch.popmark();
104 assert (HrtStopwatch.top() == 0);
105 HrtStopwatch.popmark();
106 assert (HrtStopwatch.top() == -1);
108 out.println(
"<-- HrtStopwatchTest.test0()");
111 static public void test1()
113 HrtProfiler.enter(
"test1");
114 out.println(
"--> HrtStopwatchTest.test1()");
118 out.println(
"<-- HrtStopwatchTest.test1()");
119 HrtProfiler.leave(
"test1");
122 static public void test11()
124 HrtProfiler.enter(
"test11");
125 out.println(
"--> HrtStopwatchTest.test11()");
129 out.println(
"<-- HrtStopwatchTest.test11()");
130 HrtProfiler.leave(
"test11");
133 static public void test111()
135 HrtProfiler.enter(
"test111");
136 out.println(
"--> HrtStopwatchTest.test111()");
138 out.println(
"<-- HrtStopwatchTest.test111()");
139 HrtProfiler.leave(
"test111");
142 static public void main(
String[] args)
144 out.println(
"--> HrtStopwatchTest.main()");
147 out.println(
"init stopwatch...");
148 HrtStopwatch.init(10);
149 assert (HrtStopwatch.top() == -1);
152 out.println(
"testing stopwatch...");
156 out.println(
"testing profiler...");
159 HrtProfiler.report();
161 out.println(
"closing stopwatch...");
162 HrtStopwatch.close();
164 out.println(
"<-- HrtStopwatchTest.main()");