Thread overview | |||||||||
---|---|---|---|---|---|---|---|---|---|
|
December 20, 2014 pathfinding benchmark | ||||
---|---|---|---|---|
| ||||
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. :) |
December 20, 2014 Re: pathfinding benchmark | ||||
---|---|---|---|---|
| ||||
Posted in reply to Xiaoxi | 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
|
December 20, 2014 Re: pathfinding benchmark | ||||
---|---|---|---|---|
| ||||
Posted in reply to Xiaoxi | 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
|
December 20, 2014 Re: pathfinding benchmark | ||||
---|---|---|---|---|
| ||||
Posted in reply to JN | On Saturday, 20 December 2014 at 10:36:23 UTC, JN wrote:
> 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
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.
David
|
December 20, 2014 Re: pathfinding benchmark | ||||
---|---|---|---|---|
| ||||
Posted in reply to Xiaoxi | 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
|
December 20, 2014 Re: pathfinding benchmark | ||||
---|---|---|---|---|
| ||||
Posted in reply to Théo Bueno | 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: >> 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 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. |
December 20, 2014 Re: pathfinding benchmark | ||||
---|---|---|---|---|
| ||||
Posted in reply to Théo Bueno | 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.
|
Copyright © 1999-2021 by the D Language Foundation