That's some alien Java code indeed.
int getLongestPath(ArrayList<node> nodes, int nodeID, boolean[] visited){
visited[nodeID] = true;
int dist, max=0;
for(route neighbour: nodes.get(nodeID).neighbours){
if (!visited[neighbour.dest]){
dist = neighbour.cost + getLongestPath(nodes, neighbour.dest, visited);
if (dist > max){
max = dist;
}
}
}
visited[nodeID] = false;
return max;
}
The ArrayList of nodes could be changed to an array, but I don't imagine that'd be much faster (I've always heard that ArrayLists are just as fast as arrays, except for primitives).*Edit: someone found a massive improvement, by replacing the node class with arrays, to simulate unboxing.
You should include both your old java code with the new one. Call your version "enterprise java" and the other "optimized java". If anything, that could be useful to people coding in java and having performance issue ( otherwise they'll have to look for it in git history, which they'd have no reason to).
I've added a note regarding the change, but I'm off to bed in a moment (AEST timezone). I'll separate the Java versions tomorrow.
ArrayList<route> neighbours = nodes.get(nodeID).neighbours;
for(int i=0;i<neighbours.size();i++){
route neighbour = neighbours.get(i);
Also add -Xbatch as a parameter which gives another few percentage points.Original comment is on proggit. Went from 1600ms to 900ms.
http://www.reddit.com/r/programming/comments/2pvf68/armv7_vs...