From: stephey Date: Thu, 31 Mar 2011 09:04:04 +0000 (+0000) Subject: Tried to squeeze out more performance by changing the LinkedLIsts in the Delaunay... X-Git-Url: http://plrg.eecs.uci.edu/git/?a=commitdiff_plain;h=5cf014156965d7b21ea7a7ca56013ebd7b55059a;p=IRC.git Tried to squeeze out more performance by changing the LinkedLIsts in the Delaunay port to vectors (which is closer to the original implementation of ArrayLists). Seems not to make an appreciable difference though... Added Vector.clone() and VectorIterator --- diff --git a/Robust/src/Benchmarks/oooJava/DelaunayRefinement/DirectedGraph.java b/Robust/src/Benchmarks/oooJava/DelaunayRefinement/DirectedGraph.java index e8719acd..a37fba5a 100644 --- a/Robust/src/Benchmarks/oooJava/DelaunayRefinement/DirectedGraph.java +++ b/Robust/src/Benchmarks/oooJava/DelaunayRefinement/DirectedGraph.java @@ -29,7 +29,7 @@ public class DirectedGraph implements Graph { public Iterator getInNeighbors(Node src) { GraphNode src_c = (GraphNode) src; // return Collections.unmodifiableCollection(src_c.getInNeighbors()); - return src_c.getInNeighborsCopy(); + return src_c.getInNeighborsCopy().iterator(); } public int getInNeighborsSize(Node node) { @@ -43,7 +43,7 @@ public class DirectedGraph implements Graph { public Iterator getOutNeighbors(Node src) { GraphNode src_c = (GraphNode) src; // return Collections.unmodifiableCollection(src_c.getOutNeighbors()); - return src_c.getOutNeighborsCopy(); + return src_c.getOutNeighborsCopy().iterator(); } public int getOutNeighborsSize(Node node) { @@ -73,11 +73,12 @@ public class DirectedGraph implements Graph { protected void removeConnectingEdges(GraphNode n) { GraphNode g; - for (Iterator iterator1 = n.getOutNeighborsCopy(); iterator1.hasNext(); removeNeighbor(n, g)) { + + for (Iterator iterator1 = n.getOutNeighborsCopy().iterator(); iterator1.hasNext(); removeNeighbor(n, g)) { g = (GraphNode) iterator1.next(); } - - for (Iterator iterator2 = n.getInNeighborsCopy(); iterator2.hasNext(); removeNeighbor(g, n)) { + + for (Iterator iterator2 = n.getInNeighborsCopy().iterator(); iterator2.hasNext(); removeNeighbor(g, n)) { g = (GraphNode) iterator2.next(); } diff --git a/Robust/src/Benchmarks/oooJava/DelaunayRefinement/GraphNode.java b/Robust/src/Benchmarks/oooJava/DelaunayRefinement/GraphNode.java index e8231779..755d4534 100644 --- a/Robust/src/Benchmarks/oooJava/DelaunayRefinement/GraphNode.java +++ b/Robust/src/Benchmarks/oooJava/DelaunayRefinement/GraphNode.java @@ -2,8 +2,8 @@ public class GraphNode extends Node { protected Object data; // protected List inNeighbors; // protected List outNeighbors; - protected LinkedList inNeighbors; - protected LinkedList outNeighbors; + protected Vector inNeighbors; + protected Vector outNeighbors; protected GraphNode() { super(); @@ -12,8 +12,8 @@ public class GraphNode extends Node { public GraphNode(Object n) { super(); data = n; - inNeighbors = new LinkedList(); - outNeighbors = new LinkedList(); + inNeighbors = new Vector(); + outNeighbors = new Vector(); } // public Object getData() { @@ -28,7 +28,7 @@ public class GraphNode extends Node { if (inNeighbors.contains(n)) { return false; } else { - inNeighbors.addLast(n); + inNeighbors.addElement(n); return true; } } @@ -41,24 +41,19 @@ public class GraphNode extends Node { return inNeighbors.contains(n); } - public final Iterator getInNeighbors() { - return inNeighbors.iterator(); + public final Vector getInNeighbors() { + return inNeighbors; } - public final Iterator getInNeighborsCopy() { - LinkedList l = new LinkedList(); - Iterator o = inNeighbors.iterator(); - while (o.hasNext()) { - l.addLast(o); - } - return l.iterator(); + public final Vector getInNeighborsCopy() { + return inNeighbors.clone(); } public final boolean addOutNeighbor(GraphNode n) { if (outNeighbors.contains(n)) { return false; } else { - outNeighbors.addLast(n); + outNeighbors.addElement(n); return true; } } @@ -66,21 +61,15 @@ public class GraphNode extends Node { public final boolean removeOutNeighbor(GraphNode n) { return outNeighbors.remove(n); } - public final boolean hasOutNeighbor(GraphNode n) { return outNeighbors.contains(n); } - public final Iterator getOutNeighbors() { - return outNeighbors.iterator(); + public final Vector getOutNeighbors() { + return outNeighbors; } - public final Iterator getOutNeighborsCopy() { - LinkedList l = new LinkedList(); - Iterator o = outNeighbors.iterator(); - while (o.hasNext()) { - l.addLast(o); - } - return l.iterator(); + public final Vector getOutNeighborsCopy() { + return outNeighbors.clone(); } } \ No newline at end of file diff --git a/Robust/src/Benchmarks/oooJava/DelaunayRefinement/Mesh.java b/Robust/src/Benchmarks/oooJava/DelaunayRefinement/Mesh.java index 9af7cd31..d2d26484 100644 --- a/Robust/src/Benchmarks/oooJava/DelaunayRefinement/Mesh.java +++ b/Robust/src/Benchmarks/oooJava/DelaunayRefinement/Mesh.java @@ -131,8 +131,9 @@ public class Mesh { if (!found.contains(node)) { found.add(node); Node neighbor; - for (Iterator iterator1 = mesh.getOutNeighbors(node); iterator1.hasNext(); remaining - .push(neighbor)) + + + for (Iterator iterator1 = mesh.getOutNeighbors(node); iterator1.hasNext(); remaining.push(neighbor)) neighbor = (Node) iterator1.next(); } diff --git a/Robust/src/Benchmarks/oooJava/DelaunayRefinement/SerialDelaunayRefinement.java b/Robust/src/Benchmarks/oooJava/DelaunayRefinement/SerialDelaunayRefinement.java index 344f3038..d67103c8 100644 --- a/Robust/src/Benchmarks/oooJava/DelaunayRefinement/SerialDelaunayRefinement.java +++ b/Robust/src/Benchmarks/oooJava/DelaunayRefinement/SerialDelaunayRefinement.java @@ -44,6 +44,7 @@ public class SerialDelaunayRefinement { if (runtime < mintime) { mintime = runtime; } + System.gc(); } System.out.println("minimum runtime: " + mintime + " ms"); @@ -91,7 +92,6 @@ public class SerialDelaunayRefinement { } System.gc(); - System.out.println("Done with GC"); // long id = Time.getNewTimeId(); long startTime = System.currentTimeMillis(); diff --git a/Robust/src/Benchmarks/oooJava/DelaunayRefinement/runs b/Robust/src/Benchmarks/oooJava/DelaunayRefinement/runs index 9a0c9345..f9aa7ac9 100755 --- a/Robust/src/Benchmarks/oooJava/DelaunayRefinement/runs +++ b/Robust/src/Benchmarks/oooJava/DelaunayRefinement/runs @@ -1 +1 @@ -./SerialDelaunayRefinements.bin ./input/large.2 true +./SerialDelaunayRefinements.bin ./input/massive.2 true diff --git a/Robust/src/ClassLibrary/Vector.java b/Robust/src/ClassLibrary/Vector.java index 42ab24f9..884f2a6b 100644 --- a/Robust/src/ClassLibrary/Vector.java +++ b/Robust/src/ClassLibrary/Vector.java @@ -14,6 +14,18 @@ public class Vector { this.size=0; array=new Object[size]; } + + //used for internal cloning + private Vector(int size, int capacityIncrement, Object[] array) { + this.size = size; + this.capacityIncrement = capacityIncrement; + this.array = new Object[array.length]; + System.arraycopy(array, 0, this.array, 0, size); + } + + public Vector clone() { + return new Vector(size,capacityIncrement, array); + } public boolean isEmpty() { return size==0; @@ -40,10 +52,14 @@ public class Vector { return indexOf(e)!=-1; } - public void remove(Object o) { + public boolean remove(Object o) { int in=indexOf(o); - if (in!=-1) + if (in!=-1) { removeElementAt(in); + return true; + } + + return false; } public Object elementAt(int index) { diff --git a/Robust/src/ClassLibrary/VectorIterator.java b/Robust/src/ClassLibrary/VectorIterator.java new file mode 100644 index 00000000..2b639306 --- /dev/null +++ b/Robust/src/ClassLibrary/VectorIterator.java @@ -0,0 +1,36 @@ +public class VectorIterator extends Iterator { + private int pos; + private int size; + private Vector list; + + public VectorIterator(Vector v) { + this.list = v; + this.pos = 0; + this.size = this.list.size(); + } + + /** + * Tests to see if there are any more objects to + * return. + * + * @return True if the end of the list has not yet been + * reached. + */ + public boolean hasNext() + { + return pos < size; + } + + /** + * Retrieves the next object from the list. + * + * @return The next object. + */ + public Object next() + { + if (pos == size) { + return null; //since we can't throw anything... + } + return this.list.get(pos++); + } +} \ No newline at end of file