ADTaaron-thesisarm-ehast-experimentalcleanup-dtorsdeferred_resndemanglerenumforall-pointer-decayjacob/cs343-translationjenkins-sandboxnew-astnew-ast-unique-exprnew-envno_listpersistent-indexerpthread-emulationqualifiedEnumresolv-newwith_gc
Last change
on this file since a6d70cd was
6aa537a4,
checked in by Thierry Delisle <tdelisle@…>, 7 years ago
|
Added java benchmarks
|
-
Property mode set to
100644
|
File size:
1.0 KB
|
Line | |
---|
1 | import java.util.concurrent.atomic.AtomicBoolean; |
---|
2 | |
---|
3 | public class JavaThread { |
---|
4 | public synchronized void doWait () throws InterruptedException { this.wait (); } |
---|
5 | public synchronized void doSignal() throws InterruptedException { this.notify(); } |
---|
6 | |
---|
7 | public static AtomicBoolean go = new AtomicBoolean( false ); |
---|
8 | |
---|
9 | public static class Signaller extends Thread { |
---|
10 | JavaThread j; |
---|
11 | Signaller(JavaThread j) { |
---|
12 | this.j = j; |
---|
13 | } |
---|
14 | |
---|
15 | public void run() { |
---|
16 | go.set( true ); |
---|
17 | try { |
---|
18 | while( JavaThread.go.get() ) { |
---|
19 | this.j.doSignal(); |
---|
20 | } |
---|
21 | } catch(InterruptedException trash) { |
---|
22 | |
---|
23 | } |
---|
24 | } |
---|
25 | } |
---|
26 | |
---|
27 | public static void main(String[] args) throws InterruptedException { |
---|
28 | int NoOfTimes = 50000; |
---|
29 | JavaThread j = new JavaThread(); |
---|
30 | Signaller s = new Signaller(j); |
---|
31 | s.start(); |
---|
32 | while( !JavaThread.go.get() ) { |
---|
33 | Thread.yield(); |
---|
34 | } |
---|
35 | long start = System.nanoTime(); |
---|
36 | for(int i = 1; i <= NoOfTimes; i += 1) { |
---|
37 | j.doWait(); |
---|
38 | } |
---|
39 | long end = System.nanoTime(); |
---|
40 | go.set( false ); |
---|
41 | s.join(); |
---|
42 | System.out.println( (end - start) / NoOfTimes); |
---|
43 | } |
---|
44 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.