Changeset be53b87
- Timestamp:
- Jul 29, 2019, 1:46:24 PM (5 years ago)
- Branches:
- ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum
- Children:
- 5453237
- Parents:
- 033ff37
- git-author:
- Peter A. Buhr <pabuhr@…> (07/29/19 12:40:16)
- git-committer:
- Peter A. Buhr <pabuhr@…> (07/29/19 13:46:24)
- Location:
- benchmark
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
benchmark/creation/JavaThread.java
r033ff37 rbe53b87 1 1 public class JavaThread { 2 // Simplistic low-quality Marsaglia Shift-XOR pseudo-random number generator. 3 // Bijective 4 // Cycle length for non-zero values is 4G-1. 5 // 0 is absorbing and should be avoided -- fixed point. 6 // The returned value is typically masked to produce a positive value. 7 static volatile int Ticket = 0 ; 8 9 private static int nextRandom (int x) { 10 if (x == 0) { 11 // reseed the PRNG 12 // Ticket is accessed infrequently and does not constitute a coherence hot-spot. 13 // Note that we use a non-atomic racy increment -- the race is rare and benign. 14 // If the race is a concern switch to an AtomicInteger. 15 // In addition accesses to the RW volatile global "Ticket" variable are not 16 // (readily) predictable at compile-time so the JIT will not be able to elide 17 // nextRandom() invocations. 18 x = ++Ticket ; 19 if (x == 0) x = 1 ; 20 } 21 x ^= x << 6; 22 x ^= x >>> 21; 23 x ^= x << 7; 24 return x ; 25 } 26 static int x = 2; 27 28 static private final int NoOfTimes = Integer.parseInt("10000") ; 29 2 30 public static class MyThread extends Thread { 3 31 @Override 4 32 public void run() {} 5 33 } 6 7 public static void main(String[] args) throws InterruptedException { 8 int NoOfTimes = 50000; 9 long start = System.nanoTime(); 34 public static void helper() throws InterruptedException { 10 35 for(int i = 1; i <= NoOfTimes; i += 1) { 11 JavaThread.MyThread m = new JavaThread.MyThread(); 12 m.start(); 36 MyThread m = new MyThread(); 37 x = nextRandom( x ); 38 m.start(); 13 39 m.join(); 14 40 } 41 } 42 public static void InnerMain() throws InterruptedException { 43 long start = System.nanoTime(); 44 helper(); 15 45 long end = System.nanoTime(); 16 System.out.println( (end - start) / NoOfTimes); 46 System.out.println( (end - start) / NoOfTimes ); 47 } 48 public static void main(String[] args) throws InterruptedException { 49 for (int n = Integer.parseInt("5"); --n >= 0 ; ) { 50 InnerMain(); 51 Thread.sleep(2000); // 2 seconds 52 x = nextRandom(x); 53 } 54 if ( x == 0 ) System.out.println(x); 17 55 } 18 56 } -
benchmark/ctxswitch/JavaThread.java
r033ff37 rbe53b87 1 1 public class JavaThread { 2 public static void main(String[] args) { 3 int NoOfTimes = 5000000; 4 long start = System.nanoTime(); 2 // Simplistic low-quality Marsaglia Shift-XOR pseudo-random number generator. 3 // Bijective 4 // Cycle length for non-zero values is 4G-1. 5 // 0 is absorbing and should be avoided -- fixed point. 6 // The returned value is typically masked to produce a positive value. 7 static volatile int Ticket = 0 ; 8 9 private static int nextRandom (int x) { 10 if (x == 0) { 11 // reseed the PRNG 12 // Ticket is accessed infrequently and does not constitute a coherence hot-spot. 13 // Note that we use a non-atomic racy increment -- the race is rare and benign. 14 // If the race is a concern switch to an AtomicInteger. 15 // In addition accesses to the RW volatile global "Ticket" variable are not 16 // (readily) predictable at compile-time so the JIT will not be able to elide 17 // nextRandom() invocations. 18 x = ++Ticket ; 19 if (x == 0) x = 1 ; 20 } 21 x ^= x << 6; 22 x ^= x >>> 21; 23 x ^= x << 7; 24 return x ; 25 } 26 static int x = 2; 27 28 static private final int NoOfTimes = Integer.parseInt("1000000") ; 29 30 public static void helper() { 5 31 for(int i = 1; i <= NoOfTimes; i += 1) { 6 32 Thread.yield(); 7 33 } 34 } 35 public static void InnerMain() { 36 long start = System.nanoTime(); 37 helper(); 8 38 long end = System.nanoTime(); 9 System.out.println( (end - start) / NoOfTimes); 39 System.out.println( (end - start) / NoOfTimes ); 40 } 41 public static void main(String[] args) throws InterruptedException { 42 for (int n = Integer.parseInt("5"); --n >= 0 ; ) { 43 InnerMain(); 44 Thread.sleep(2000); // 2 seconds 45 x = nextRandom(x); 46 } 47 if ( x == 0 ) System.out.println(x); 10 48 } 11 49 } -
benchmark/mutex/JavaThread.java
r033ff37 rbe53b87 1 1 public class JavaThread { 2 public synchronized void noop() {} 2 // Simplistic low-quality Marsaglia Shift-XOR pseudo-random number generator. 3 // Bijective 4 // Cycle length for non-zero values is 4G-1. 5 // 0 is absorbing and should be avoided -- fixed point. 6 // The returned value is typically masked to produce a positive value. 7 static volatile int Ticket = 0 ; 3 8 4 public static void main(String[] args) { 5 int NoOfTimes = 5000000; 9 private static int nextRandom (int x) { 10 if (x == 0) { 11 // reseed the PRNG 12 // Ticket is accessed infrequently and does not constitute a coherence hot-spot. 13 // Note that we use a non-atomic racy increment -- the race is rare and benign. 14 // If the race is a concern switch to an AtomicInteger. 15 // In addition accesses to the RW volatile global "Ticket" variable are not 16 // (readily) predictable at compile-time so the JIT will not be able to elide 17 // nextRandom() invocations. 18 x = ++Ticket ; 19 if (x == 0) x = 1 ; 20 } 21 x ^= x << 6; 22 x ^= x >>> 21; 23 x ^= x << 7; 24 return x ; 25 } 26 static int x = 2; 27 28 static private final int NoOfTimes = Integer.parseInt("100000000") ; 29 30 public synchronized void noop() { 31 x = nextRandom( x ); 32 } 33 public static void helper() throws InterruptedException { 6 34 JavaThread j = new JavaThread(); 7 long start = System.nanoTime(); 35 // Inhibit biased locking ... 36 x = (j.hashCode() ^ System.identityHashCode(j)) | 1 ; 8 37 for(int i = 1; i <= NoOfTimes; i += 1) { 38 x = nextRandom(x); 9 39 j.noop(); 10 40 } 41 } 42 public static void InnerMain() throws InterruptedException { 43 long start = System.nanoTime(); 44 helper(); 11 45 long end = System.nanoTime(); 12 System.out.println( (end - start) / NoOfTimes); 46 System.out.println( (end - start) / NoOfTimes ); 47 } 48 public static void main(String[] args) throws InterruptedException { 49 for (int n = Integer.parseInt("5"); --n >= 0 ; ) { 50 InnerMain(); 51 Thread.sleep(2000); // 2 seconds 52 x = nextRandom(x); 53 } 54 if ( x == 0 ) System.out.println(x); 13 55 } 14 56 } -
benchmark/schedint/JavaThread.java
r033ff37 rbe53b87 1 1 class Monitor { 2 2 public static volatile Boolean go = false; 3 public static volatile Boolean next = false; 3 4 } 4 5 … … 13 14 while( Monitor.go ) { 14 15 synchronized(this.m) { 16 Monitor.next = false; 15 17 this.m.notify(); 16 18 } 19 while( ! Monitor.next && Monitor.go ); // spin until woken 17 20 } 18 21 } … … 20 23 21 24 public class JavaThread { 22 public static void main(String[] args) throws InterruptedException { 23 int NoOfTimes = 50000; 25 // Simplistic low-quality Marsaglia Shift-XOR pseudo-random number generator. 26 // Bijective 27 // Cycle length for non-zero values is 4G-1. 28 // 0 is absorbing and should be avoided -- fixed point. 29 // The returned value is typically masked to produce a positive value. 30 static volatile int Ticket = 0 ; 31 32 private static int nextRandom (int x) { 33 if (x == 0) { 34 // reseed the PRNG 35 // Ticket is accessed infrequently and does not constitute a coherence hot-spot. 36 // Note that we use a non-atomic racy increment -- the race is rare and benign. 37 // If the race is a concern switch to an AtomicInteger. 38 // In addition accesses to the RW volatile global "Ticket" variable are not 39 // (readily) predictable at compile-time so the JIT will not be able to elide 40 // nextRandom() invocations. 41 x = ++Ticket ; 42 if (x == 0) x = 1 ; 43 } 44 x ^= x << 6; 45 x ^= x >>> 21; 46 x ^= x << 7; 47 return x ; 48 } 49 static int x = 2; 50 51 static private final int NoOfTimes = Integer.parseInt("1000000") ; 52 53 public static void helper( Monitor m ) throws InterruptedException { 54 for(int i = 1; i <= NoOfTimes; i += 1) { 55 m.wait(); // relase monitor lock 56 m.next = true; 57 } 58 } 59 public static void InnerMain() throws InterruptedException { 24 60 Monitor m = new Monitor(); 25 61 long start, end; … … 31 67 } 32 68 start = System.nanoTime(); 33 for(int i = 1; i <= NoOfTimes; i += 1) { 34 m.wait(); 35 } 69 helper( m ); 36 70 end = System.nanoTime(); 37 71 } … … 40 74 System.out.println( (end - start) / NoOfTimes); 41 75 } 76 public static void main(String[] args) throws InterruptedException { 77 for (int n = Integer.parseInt("5"); --n >= 0 ; ) { 78 InnerMain(); 79 Thread.sleep(2000); // 2 seconds 80 x = nextRandom(x); 81 } 82 if ( x == 0 ) System.out.println(x); 83 } 42 84 }
Note: See TracChangeset
for help on using the changeset viewer.