Re:ARMv7 vs. x86-64: Pathfinding benchmark of C++, D, Go, Ni...
by logicchains on Sunday December 21, 2014 @06:07AM
(#8779477)
Nice, your cached version is the fastest by far, although it uses a different algorithm. Running with `node js.js` without the cache, it takes around 6 seconds, close to Dart and Haskell.
Re:ARMv7 vs. x86-64: Pathfinding benchmark of C++, D, Go, Ni...
by brucer on Sunday December 21, 2014 @02:23PM
(#8780601)
I just realized I overthought the caching scheme, and removing one check made it 3x faster :)
function getLongestPathCached(nodes, nodeid, visited, depth) {
var idx;
visited |= 1 << nodeid;
idx = (visited * 32) + nodeid;
if (visitCache[idx]) {
return visitCache[idx];
}
var neighbours = nodes[nodeid];
var max = 0
for(var i=0;i<neighbours.length;i++) {
if (!(visited & (1 << neighbours[i].dst))) {
var dist = neighbours[i].cost + getLongestPathCached(nodes, neighbours[i].dst, visited, depth+1);
if (dist > max) {
max = dist
}
}
}
visitCache[idx] = max;
return max;
}
Re:ARMv7 vs. x86-64: Pathfinding benchmark of C++, D, Go, Ni...
by logicchains on Monday December 22, 2014 @07:23AM
(#8782836)
Nice! That's almost as fast as the C++ one using caching; your algorithm must be better.
I was curious how fast Javascript would run this, so I ported the lua example over, it ran in 2200msec on my mac laptop. I'm not sure it's a great comparison benchmark however, because there are some obvious optimizations you can make. I added a simple cache to avoid recalculating travel costs for leaves and it now runs in 150msec.
var fs = require('fs');