-
Notifications
You must be signed in to change notification settings - Fork 133
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Not building with newest LDC D compiler #378
Comments
So it seems the issue is fixed. And will be available in 1.32.1 version of LDC. |
I couldn't compile the binary tree 1.d solution until I fixed the imports... not sure if that was written for very old D versions? Here's what works for me with D v2: @safe:
import std.stdio;
import std.conv;
import std.algorithm.comparison;
import std.format;
extern(C) __gshared string[] rt_options = [ "gcopt=minPoolSize:300" ];
const MIN_DEPTH = 4;
class Node {
private Node left;
private Node right;
this(Node left, Node right)
{
this.left = left;
this.right = right;
}
int check() {
auto r = 1;
auto ln = this.left;
auto rn = this.right;
if (ln) {
r += ln.check();
}
if (rn) {
r += rn.check();
}
return r;
}
static Node create(int depth) {
if (depth > 0) {
auto d = depth - 1;
return new Node(Node.create(d), Node.create(d));
}
return new Node(null, null);
}
}
void main(string[] args)
{
auto n = args.length > 1 ? args[1].to!int() : 6;
auto maxDepth = max(MIN_DEPTH + 2, n);
auto stretchDepth = maxDepth + 1;
auto stretchTree = Node.create(stretchDepth);
writeln(format("stretch tree of depth %d\t check: %d", stretchDepth, stretchTree.check()));
auto longLivedTree = Node.create(maxDepth);
for (int depth = MIN_DEPTH; depth <= maxDepth; depth += 2) {
auto iterations = 1 << (maxDepth - depth + MIN_DEPTH);
auto sum = 0;
for (auto i = 0; i < iterations; i++) {
sum += Node.create(depth).check();
}
writeln(format("%d\t trees of depth %d\t check: %d", iterations, depth, sum));
}
writeln(format("long lived tree of depth %d\t check: %d", maxDepth, longLivedTree.check()));
}
This is much slower than Java and Dart, for example, which seem very strange to me. Anyone has any idea why that would be? I suppose this problem is testing mostly the GC and speed of allocation, but still D shouldn't be 5x slower as it currently is, but I couldn't speed this up myself as I don't know D very well. |
Hi @renatoathaydes Which compiler version are you using? Regarding the speed - you can see that on top of the list in this problem languages with VM - Dart and JVM like.. |
Ok. I've made some changes: more close to other solutions.. moved from class to struct. And it is working a bit faster on my machine.
For comparison of performance:
Current D version:
Updated D version:
|
Hi @cyrusmsk I was using gdc and that doesn't work on gdc. I am testing this on Linux. I can compile your code using DMD and it does run, and is a bit faster. DMD time: ➜ d dmd -of=main -O main.d
➜ d time ./main 18
stretch tree of depth 19 check: 1048575
262144 trees of depth 4 check: 8126464
65536 trees of depth 6 check: 8323072
16384 trees of depth 8 check: 8372224
4096 trees of depth 10 check: 8384512
1024 trees of depth 12 check: 8387584
256 trees of depth 14 check: 8388352
64 trees of depth 16 check: 8388544
16 trees of depth 18 check: 8388592
long lived tree of depth 18 check: 524287
./main 18 1.62s user 0.12s system 99% cpu 1.740 total
avg shared (code): 0 KB
avg unshared (data/stack): 0 KB
total (sum): 0 KB
max memory: 313 MB
page faults from disk: 0
other page faults: 79522 LDC2:
I was surprised that DMD gets the same speed as LDC. For reference, here's the Dart times (which I submitted in a PR), which is faster than the #1 Java solution (so this should be faster than the Kotlin one as well):
So D is still much slower, disappointingly. |
Usually Dart will be much slower than D. Just this algorithm that proposed to be used for this problem not doing well.. |
For example you can find another approach of BinaryTrees.. https://github.com/BinaryTrees |
And there are also optimized solutions https://benchmarksgame-team.pages.debian.net/benchmarksgame/performance/binarytrees.html |
I also ran a HTTP Server and Dart again was quite a bit faster. In which problems is Dart slower? |
Many of them actually. https://programming-language-benchmarks.vercel.app/dart-vs-d |
The HTTP Server I tried was not from this repository but from the "canonical" servers in each language (Dart has one in the stdlib and for D I used Vibe.d). In the comparisons page you linked, D is faster in some, slower in some, much faster in some, much slower in some, but mostly it's pretty close - with D perhaps having at most a small edge ... so I think your assertion that Dart is much slower than D doesn't reflect that page at all. |
Let's check closely. For more accurate analysis. Where Dart is faster:
|
Ok. With help of 'brianush1' the code for Coro-prime-sieve was prepared. It's slower than Go, but should be close in performance to Rust/Crystal I think. And I assume faster than Dart. import core.thread;
import std;
import std.outbuffer: OutBuffer;
class Generator(T) : Fiber {
private T value;
this(void delegate() dg) {
super(dg);
}
static void yield(T value) {
(cast(Generator!T) Fiber.getThis()).value = value;
Fiber.yield();
}
T getNext() {
call();
return value;
}
int opApply(scope int delegate(T) dg) {
int result = 0;
while (state != State.TERM) {
result = dg(getNext());
if (result)
break;
}
return result;
}
}
auto generate() {
return new Generator!long({
long i = 2;
while (true) {
Generator!long.yield(i);
i += 1;
}
});
}
auto filter(Generator!long ch, long prime) {
return new Generator!long({
foreach (i; ch)
if (i % prime != 0)
Generator!long.yield(i);
});
}
void main(string[] args) {
long n = args.length > 1 ? args[1].to!long: 10;
auto buf = new OutBuffer();
scope(exit)
write(buf.toString());
Generator!long ch = generate();
foreach (i; 0 .. n) {
long prime = ch.getNext();
buf.writef("%d\n",prime);
ch = filter(ch, prime);
}
} |
Not sure if it's valid, but D has a very fast HTTP server as well: https://github.com/tchaloupka/httparsed Also, are you also trying to speed up the Dart solution? |
D server unfortunately not very fast( httpparser is good yes.
No, I’ve never worked with Dart |
Ok, but then I suggest you avoid making claims about Dart being much slower than whatever. |
Do you know type of programs, algorithms or something where Dart will have same performance as C++/Rust? |
I don't know why you're asking about that, it has nothing to do with this thread. My original question was why D was running 2 to 3 times slower than Dart, which I found strange... but it seems quite a few Dart examples in this repo are faster than D... you then made an unfounded claim that Dart is much slower than D. I feel I have to remind you of a non-motivation of the benchmark games:
|
Please sorry if I sound offensive or something bad to Dart. I haven’t got any of these intentions. For example, I thought it is a common knowledge that languages like JS, Ruby and Python in general quite slow in comparison to languages like C++/Rust/D. So I thought that Dart is from the first category languages. It doesn’t mean that it is bad or something. |
Answering at your question: it is because bad implementation in D, or some rules of the benchmark. |
@cyrusmsk no offense taken, I understand where your impression comes from and I think you're right that Dart is normally placed in the same category as JS and Python... but the interesting thing is that since Dart's turn to a fully static type system with null-safe and compilation directly to binary executables, it became a lot closer to languages like D and Go, actually... I think it's doing very well in the performance metrics I've seen (including this benchmark) so perhaps it's time for Dart to be considered in a different light. I want to also mention I have nothing against D, to the contrary I am currently learning it and I like it a lot... and I understand that you're correct that it can achieve the same performance as C if you get out of your way to optimise it (though as you mention, the stdlib seems to not prioritize performance). I know Dart much better than I know D, but am thinking of using D more and more because of its ability to go "lower" than Dart (and my other languages, Java, Kotlin, JS, Groovy...) and my unfortunate distaste of Rust, which would absolutely be the most obvious choice today (it's a great language, but the combination of requiring a large number of libraries for anything and the annoyingly slow compiler made me unable to continue using it). That should explain why I reached out to figure out what was going on with D not being much faster than Dart from my initial impressions! It's a lot clearer now what's going on. |
Just found this issue in my fork and want to warn you @hanabi1224. So before merging the next PR maybe we could specify the version of compiler in build-d.yaml
The issue in the library's GitHub is already created. I will update this thread when new information will come.
Sorry for inconvenience.
The text was updated successfully, but these errors were encountered: