digitalmars.D - pathfinding benchmark
- Xiaoxi (2/2) Dec 20 2014 http://www.reddit.com/r/programming/comments/2pvf68/armv7_vs_x8664_pathf...
- JN (2/4) Dec 20 2014 except for the fact that writeln didn't work :x
- David Nadlinger (5/10) Dec 20 2014 That's probably in reference to ARM. To be honest, I'm quite
- bearophile (92/94) Dec 20 2014 A little better D code:
- =?UTF-8?B?IlRow6lv?= Bueno" (6/8) Dec 20 2014 Look at the last results, C++ got updated.
- =?UTF-8?B?IlRow6lv?= Bueno" (5/14) Dec 20 2014 Ah ah, someone forgot a multiplication somewhere, I guess :)
- MattCoder (5/7) Dec 20 2014 According to the site:
http://www.reddit.com/r/programming/comments/2pvf68/armv7_vs_x8664_pathfinding_benchmark_of_c_d_go/ didnt analyse the code, but D did quite well. :)
Dec 20 2014
On Saturday, 20 December 2014 at 10:12:40 UTC, Xiaoxi wrote:http://www.reddit.com/r/programming/comments/2pvf68/armv7_vs_x8664_pathfinding_benchmark_of_c_d_go/ didnt analyse the code, but D did quite well. :)except for the fact that writeln didn't work :x
Dec 20 2014
On Saturday, 20 December 2014 at 10:36:23 UTC, JN wrote:On Saturday, 20 December 2014 at 10:12:40 UTC, Xiaoxi wrote:That's probably in reference to ARM. To be honest, I'm quite surprised that the benchmark even worked that well, given the current state of LDC ARM support. Davidhttp://www.reddit.com/r/programming/comments/2pvf68/armv7_vs_x8664_pathfinding_benchmark_of_c_d_go/ didnt analyse the code, but D did quite well. :)except for the fact that writeln didn't work :x
Dec 20 2014
Xiaoxi:http://www.reddit.com/r/programming/comments/2pvf68/armv7_vs_x8664_pathfinding_benchmark_of_c_d_go/ didnt analyse the code, but D did quite well. :)A little better D code: import std.stdio, std.file, std.conv, std.string, std.datetime; struct Route { uint dest, cost; } alias Node = Route[]; Node[] readPlaces() { auto lines = "agraph".File.byLine; immutable numNodes = lines.front.to!uint; lines.popFront; auto nodes = new Node[numNodes]; foreach (const line; lines) { immutable nums = line.split.to!(uint[]); if (nums.length < 3) break; nodes[nums[0]] ~= Route(nums[1], nums[2]); } return nodes; } uint getLongestPath(in Node[] nodes, in uint nodeID, bool[] visited) pure nothrow safe nogc { visited[nodeID] = true; typeof(return) dMax = 0; foreach (immutable neighbour; nodes[nodeID]) if (!visited[neighbour.dest]) { immutable dist = neighbour.cost + getLongestPath(nodes, neighbour.dest, visited); if (dist > dMax) dMax = dist; } visited[nodeID] = false; return dMax; } void main() { const nodes = readPlaces; auto visited = new bool[nodes.length]; StopWatch sw; sw.start; immutable len = getLongestPath(nodes, 0, visited); sw.stop; printf("%d language D %d\n", len, sw.peek.msecs); } I don't remember if the D entry gets faster with ldc2 if nodes is immutable, this is a version that keeps it immutable as in the original code: import std.stdio, std.file, std.conv, std.string, std.datetime, std.exception; struct Route { uint dest, cost; } alias Node = Route[]; Node[] readPlaces() { auto lines = "agraph".File.byLine; immutable numNodes = lines.front.to!uint; lines.popFront; auto nodes = new Node[numNodes]; foreach (const line; lines) { immutable nums = line.split.to!(uint[]); if (nums.length < 3) break; nodes[nums[0]] ~= Route(nums[1], nums[2]); } return nodes; } uint getLongestPath(immutable Node[] nodes, in uint nodeID, bool[] visited) pure nothrow safe nogc { visited[nodeID] = true; typeof(return) dMax = 0; foreach (immutable neighbour; nodes[nodeID]) if (!visited[neighbour.dest]) { immutable dist = neighbour.cost + getLongestPath(nodes, neighbour.dest, visited); if (dist > dMax) dMax = dist; } visited[nodeID] = false; return dMax; } void main() { immutable nodes = readPlaces.assumeUnique; auto visited = new bool[nodes.length]; StopWatch sw; sw.start; immutable len = getLongestPath(nodes, 0, visited); sw.stop; printf("%d language D %d\n", len, sw.peek.msecs); } But I think this is probably not necessary. If you want you can submit the code to the original tester. Bye, bearophile
Dec 20 2014
On Saturday, 20 December 2014 at 10:12:40 UTC, Xiaoxi wrote:http://www.reddit.com/r/programming/comments/2pvf68/armv7_vs_x8664_pathfinding_benchmark_of_c_d_go/ didnt analyse the code, but D did quite well. :)Look at the last results, C++ got updated. x86-64 Language Runtime (ms) C++ 1.74439 D 1828
Dec 20 2014
On Saturday, 20 December 2014 at 14:37:40 UTC, Théo Bueno wrote:On Saturday, 20 December 2014 at 10:12:40 UTC, Xiaoxi wrote:Ah ah, someone forgot a multiplication somewhere, I guess :) https://github.com/logicchains/LPATHBench/commit/47d5f676f278b8d8ba7c415ff9ef6dea6666c5cf Anyway this benchmark and these numbers are crap, using the provided makefile I have totally different results on my laptop.http://www.reddit.com/r/programming/comments/2pvf68/armv7_vs_x8664_pathfinding_benchmark_of_c_d_go/ didnt analyse the code, but D did quite well. :)Look at the last results, C++ got updated. x86-64 Language Runtime (ms) C++ 1.74439 D 1828
Dec 20 2014
On Saturday, 20 December 2014 at 14:51:54 UTC, Théo Bueno wrote:Anyway this benchmark and these numbers are crap, using the provided makefile I have totally different results on my laptop.According to the site: "...Feel free to submit improvements to the implementations!" :) Matheus.
Dec 20 2014