Any improvements you can see? The 'inner loop' of the code is:
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.
I don't think this improvement is really fair though. Everybody heard the same thing as you did : arraylist are ok performance wise. The optimisation of using arrays and static global variables and remove use of any object isn't something that leads to readable code in the long run, nor is it the code your regularely see in everyday software.
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).
Managed to get a 22% improvement on Core i7 OSX / Oracle JDK8 by replacing the for iterator-style loop with a C style one. Am I missing something because this shouldn't be faster.
*Edit: someone found a massive improvement, by replacing the node class with arrays, to simulate unboxing.