W
Wizumwalt
Hey all, well, I finally got a profiler to work and my code was simple
enough that what I thought it was doing, it actually was doing, so I'm
still at a loss as to why it's so slow. I'm still trying to learn the
profiler a bit better to use, cause it took about 4 hours before I
could get any results after running the following code (literally, I
left it running for 4 hours while it was chugging away in this section
of code w/ the profiler running, my machine has 512Mb RAM).
So now I'm posting my code and maybe someone could tell me why it takes
25 seconds to run this w/o debugging. The section within '---' is what
I've timed to take 25 seconds and the supporting code is below.
Everything that is prefixed w/ either get or set is exactly that.
enough that what I thought it was doing, it actually was doing, so I'm
still at a loss as to why it's so slow. I'm still trying to learn the
profiler a bit better to use, cause it took about 4 hours before I
could get any results after running the following code (literally, I
left it running for 4 hours while it was chugging away in this section
of code w/ the profiler running, my machine has 512Mb RAM).
So now I'm posting my code and maybe someone could tell me why it takes
25 seconds to run this w/o debugging. The section within '---' is what
I've timed to take 25 seconds and the supporting code is below.
Everything that is prefixed w/ either get or set is exactly that.
Code:
// --- time start
// elements is a HashMap of 10676 in size.
Iterator eKeyIter = elements.keySet().iterator();
for (Iterator iter = elements.values().iterator(); iter.hasNext();) {
Element elem = (Element)iter.next();
if (elem.getShape() == ElementSupport.TRIANGLE) {
ttl++;
buildEdgeList(elem);
}
}
// --- time ends (25 seconds)
public void buildEdgeList(Element elem) {
WingedEdge[] wEdges = new
WingedEdge[ElementSupport.TRIANGLE_EDGE_COUNT];
for (int edge = 0; edge < ElementSupport.TRIANGLE_EDGE_COUNT;
edge++) { edgeGUID++;
wEdges[edge] = new WingedEdge(edgeGUID);
if (edge <= 1) {
wEdges[edge].setStartVertexId(elem.getVertex(edge));
wEdges[edge].setEndVertexId(elem.getVertex(edge + 1));
wEdges[edge].setRightFace(findAdjacentFace(elem.getId(),
elem.getVertex(edge), elem.getVertex(edge + 1)));
}
else {
wEdges[edge].setStartVertexId(elem.getVertex(2));
wEdges[edge].setEndVertexId(elem.getVertex(0));
wEdges[edge].setRightFace(findAdjacentFace(elem.getId(),
elem.getVertex(2), elem.getVertex(0)));
}
wEdges[edge].setLeftFace(elem.getId());
Triangle tri = (Triangle) elem;
tri.setEdge(edge, wEdges[edge]);
}
traverseEdges(wEdges);
}
public void traverseEdges(WingedEdge[] weds) {
for (int edge = 0; edge < ElementSupport.TRIANGLE_EDGE_COUNT;
edge++) {
switch (edge) {
case 0:
weds[edge].setPredecessor(ElementSupport.CCW, weds[2].getId());
weds[edge].setSuccessor(ElementSupport.CCW, weds[1].getId());
break;
case 1:
weds[edge].setPredecessor(ElementSupport.CCW, weds[0].getId());
weds[edge].setSuccessor(ElementSupport.CCW, weds[2].getId());
break;
case 2:
weds[edge].setPredecessor(ElementSupport.CCW,
weds[1].getId());
weds[edge].setSuccessor(ElementSupport.CCW,
weds[0].getId());
break;
}
edgeList.add(weds[edge]);
}
return;
}
public int findAdjacentFace(int source, int start, int end) {
Iterator eKeyIter = elements.keySet().iterator();
while (eKeyIter.hasNext()) {
Element elem = (Element) elements.get(eKeyIter.next());
if (elem.getId() == source) {
// found the exact same element so continue on.
continue;
}
if (elem.getShape() == ElementSupport.TRIANGLE) {
for (int i = 0; i < ElementSupport.TRIANGLE_EDGE_COUNT; i++) {
if (i <= 1) {
if (elem.getVertex(i) == end &&
elem.getVertex(i + 1) == start) {
return elem.getId();
}
}
else {
if (elem.getVertex(2) == end &&
elem.getVertex(0) == start) {
return elem.getId();
}
}
}
}
}
return 0;
}