ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/test/loops/Sync100M.java
Revision: 1.7
Committed: Mon Aug 10 03:13:33 2015 UTC (8 years, 8 months ago) by jsr166
Branch: MAIN
CVS Tags: HEAD
Changes since 1.6: +0 -1 lines
Log Message:
delete unwanted blank lines

File Contents

# User Rev Content
1 dl 1.2 /*
2     * Written by Doug Lea with assistance from members of JCP JSR-166
3     * Expert Group and released to the public domain, as explained at
4 jsr166 1.6 * http://creativecommons.org/publicdomain/zero/1.0/
5 dl 1.2 */
6 dl 1.1
7     class Sync100M {
8     public static void main(String[] args) throws Exception {
9 jsr166 1.4 int x = loop((int) System.nanoTime(), 100000);
10 dl 1.1 x = loop(x, 100000);
11     x = loop(x, 100000);
12     long start = System.nanoTime();
13     x = loop(x, 100000000);
14     if (x == 0) System.out.print(" ");
15     long time = System.nanoTime() - start;
16 jsr166 1.4 double secs = (double) time / 1000000000.0;
17 dl 1.1 System.out.println("time: " + secs);
18     start = System.nanoTime();
19     x = loop(x, 100000000);
20     if (x == 0) System.out.print(" ");
21     time = System.nanoTime() - start;
22 jsr166 1.4 secs = (double) time / 1000000000.0;
23 dl 1.1 System.out.println("time: " + secs);
24     }
25    
26     static final Object obj = new Object();
27 jsr166 1.3
28 dl 1.1 static int loop(int x, int iters) {
29     for (int i = iters; i > 0; --i) {
30 jsr166 1.5 synchronized (obj) {
31 dl 1.1 x = x * 134775813 + 1;
32     }
33     }
34     return x;
35     }
36 jsr166 1.3
37 dl 1.1 }