ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/test/loops/Sync100M.java
Revision: 1.1
Committed: Mon May 2 19:19:38 2005 UTC (19 years ago) by dl
Branch: MAIN
Log Message:
Put misc performance tests into CVS

File Contents

# Content
1
2 class Sync100M {
3 public static void main(String[] args) throws Exception {
4 int x = loop((int)System.nanoTime(), 100000);
5 x = loop(x, 100000);
6 x = loop(x, 100000);
7 long start = System.nanoTime();
8 x = loop(x, 100000000);
9 if (x == 0) System.out.print(" ");
10 long time = System.nanoTime() - start;
11 double secs = (double)time / 1000000000.0;
12 System.out.println("time: " + secs);
13 start = System.nanoTime();
14 x = loop(x, 100000000);
15 if (x == 0) System.out.print(" ");
16 time = System.nanoTime() - start;
17 secs = (double)time / 1000000000.0;
18 System.out.println("time: " + secs);
19
20 }
21
22 static final Object obj = new Object();
23
24 static int loop(int x, int iters) {
25 for (int i = iters; i > 0; --i) {
26 synchronized(obj) {
27 x = x * 134775813 + 1;
28 }
29 }
30 return x;
31 }
32
33 }