Skip to content
Snippets Groups Projects
Commit f627db0c authored by Christian Wulf's avatar Christian Wulf
Browse files

array wrapper costs performance

parent 3ac64561
No related branches found
No related tags found
No related merge requests found
......@@ -3,6 +3,7 @@
-for loop with super type vs. concrete type (reason: due to less JIT optimization possibilities)
-passing by argument vs. instance variable (reason: unknown)
-pipe with array vs. single element (reason: unknown)
-access via array wrapper vs. array directly
-
[irrelevant w.r.t. overhead]
......@@ -16,8 +17,10 @@
2: 7400 ns
8: 1200 ns (iterative; argument/return w/o pipe)
9: 9400 ns (queued pipe)
10: 4900 ns (single element pipe)
11: 7400 ns (fixed sized pipe)
9: 9400 ns (executeWithPorts: queued pipe)
10: 4900 ns (executeWithPorts: single element pipe)
11: 7400 ns (executeWithPorts: fixed sized pipe)
11: 8600 ns (executeWithPorts: fixed sized pipe with CircularArray(int))
11: 8200 ns (executeWithPorts: fixed sized pipe with CircularArray(int) w/o mask)
12: 3300 ns (recursive; argument/return w/o pipe)
13: 3300 ns (recursive; argument/return w/o pipe; w/o pipeline class)
package teetime.examples.throughput.methodcall;
public final class ArrayWrapper<T> {
private final T[] elements;
// private int lastFreeIndex;
@SuppressWarnings("unchecked")
public ArrayWrapper(final int initialCapacity) {
super();
this.elements = (T[]) new Object[initialCapacity];
}
public final T get(final int index) {
return this.elements[index];
}
public final void put(final int index, final T element) {
this.elements[index] = element;
}
public final int getCapacity() {
return this.elements.length;
}
}
......@@ -21,9 +21,12 @@ public abstract class ConsumerStage<I, O> extends AbstractStage<I, O> {
@Override
public void executeWithPorts() {
I element = this.getInputPort().receive();
this.setReschedulable(!this.getInputPort().pipe.isEmpty());
this.execute5(element);
// this.setReschedulable(!this.getOutputPort().pipe.isEmpty());
// this.send(result);
// if (!this.getOutputPort().pipe.isEmpty()) {
// super.executeWithPorts();
......
......@@ -3,6 +3,7 @@ package teetime.examples.throughput.methodcall;
public class FixedSizedPipe<T> implements IPipe<T> {
private final T[] elements = (T[]) new Object[4];
// private final ArrayWrapper<T> elements = new ArrayWrapper<T>(2);
private int lastFreeIndex;
public static <T> void connect(final OutputPort<T> sourcePort, final InputPort<T> targetPort) {
......@@ -13,12 +14,24 @@ public class FixedSizedPipe<T> implements IPipe<T> {
@Override
public void add(final T element) {
if (this.lastFreeIndex == this.elements.length) {
// if (this.lastFreeIndex == this.elements.getCapacity()) {
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
// grow
}
this.elements[this.lastFreeIndex++] = element;
// this.elements.put(this.lastFreeIndex++, element);
}
@Override
public T removeLast() {
return this.elements[--this.lastFreeIndex];
// return this.elements.get(--this.lastFreeIndex);
}
@Override
......@@ -28,7 +41,8 @@ public class FixedSizedPipe<T> implements IPipe<T> {
@Override
public T readLast() {
return this.elements[this.lastFreeIndex];
return this.elements[this.lastFreeIndex - 1];
// return this.elements.get(this.lastFreeIndex - 1);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment