Skip to content

Commit

Permalink
match measurement method from QueuePerfTest
Browse files Browse the repository at this point in the history
  • Loading branch information
nitsanw committed Dec 28, 2014
1 parent 3929b87 commit 469bbdb
Showing 1 changed file with 24 additions and 19 deletions.
Expand Up @@ -13,6 +13,7 @@
*/ */
package org.jctools.handrolled.throughput.spsc; package org.jctools.handrolled.throughput.spsc;


import org.jctools.handrolled.throughput.spsc.QueuePerfTest.Producer;
import org.jctools.queues.QueueByTypeFactory; import org.jctools.queues.QueueByTypeFactory;


import java.util.Queue; import java.util.Queue;
Expand All @@ -39,48 +40,52 @@ public static void main(final String[] args) throws Exception {
System.out.format("summary,BusyQueuePerfTest,%s,%d\n", queue.getClass().getSimpleName(), sum / 10); System.out.format("summary,BusyQueuePerfTest,%s,%d\n", queue.getClass().getSimpleName(), sum / 10);
} }


private static long performanceRun(final int runNumber, final Queue<Integer> queue) throws Exception { private static long performanceRun(int runNumber, Queue<Integer> queue) throws Exception {
final long start = System.nanoTime(); Producer p = new Producer(queue);
final Producer p = new Producer(queue); Thread thread = new Thread(p);
final Thread thread = new Thread(p); thread.start();// producer will timestamp start
thread.start();


Integer result; Integer result;
int i = REPETITIONS; int i = REPETITIONS;
int f = 0; int queueEmpty = 0;
do { do {
while (null == (result = queue.poll())) { while (null == (result = queue.poll())) {
f++; queueEmpty++;
} }
} while (0 != --i); } while (0 != --i);

long end = System.nanoTime();

thread.join(); thread.join();

long duration = end - p.start;
final long duration = System.nanoTime() - start; long ops = (REPETITIONS * 1000L * 1000L * 1000L) / duration;
final long ops = (REPETITIONS * 1000L * 1000L * 1000L) / duration; String qName = queue.getClass().getSimpleName();
System.out.format("%d - ops/sec=%,d - %s result=%d failed.poll=%d failed.offer=%d\n", System.out.format("%d - ops/sec=%,d - %s result=%d failed.poll=%d failed.offer=%d\n", runNumber, ops,
Integer.valueOf(runNumber), Long.valueOf(ops), qName, result, queueEmpty, p.queueFull);
queue.getClass().getSimpleName(), result,f,p.fails);
return ops; return ops;
} }


public static class Producer implements Runnable { public static class Producer implements Runnable {
private final Queue<Integer> queue; private final Queue<Integer> queue;
int fails=0; int queueFull = 0;
public Producer(final Queue<Integer> queue) { long start = 0;

public Producer(Queue<Integer> queue) {
this.queue = queue; this.queue = queue;
} }


public void run() { public void run() {
final Queue<Integer> q = queue;
int i = REPETITIONS; int i = REPETITIONS;
int f=0; int f = 0;
Queue<Integer> q = queue;
long s = System.nanoTime();
do { do {
while (!q.offer(TEST_VALUE)) { while (!q.offer(TEST_VALUE)) {
f++; f++;
} }
} while (0 != --i); } while (0 != --i);
fails = f;
queueFull = f;
start = s;
} }
} }
} }

0 comments on commit 469bbdb

Please sign in to comment.