www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - How fast is D compared to C++?

reply Jonathan M Davis <jmdavisProg gmx.com> writes:
I just thought that I'd point out this question on stackoverflow for those of
you 
who don't regularly frequent stackoverflow. It has some fairly interesting info 
(such as in being faster than const ref - I would have guessed the opposite):

http://stackoverflow.com/questions/5142366/how-fast-is-d-compared-to-c

- Jonathan M Davis
Mar 02 2011
parent reply Trass3r <un known.com> writes:
 (such as in being faster than const ref - I would have guessed the  
 opposite):
I just can't imagine why in should be faster than const ref.
Mar 02 2011
parent reply Bekenn <leaveme alone.com> writes:
On 3/2/11 11:40 AM, Trass3r wrote:
 I just can't imagine why in should be faster than const ref.
The use of ref introduces a level of indirection. I suspect the writer was trying to avoid copying array elements -- unnecessary, since vector_t was defined as a dynamic array, where only the bounds are passed. With ref, every access to a vector_t object involves a pointer dereference. Take out the ref, and const should behave identically to in. (It had better -- in and const are synonyms!)
Mar 02 2011
next sibling parent reply bearophile <bearophileHUGS lycos.com> writes:
Bekenn:

 The use of ref introduces a level of indirection.
This is correct. But a minimally decent compiler must be able to remove this indirection where possible, like here, and produce efficient code. Bye, bearophile
Mar 02 2011
parent reply Walter Bright <newshound2 digitalmars.com> writes:
bearophile wrote:
 Bekenn:
 
 The use of ref introduces a level of indirection.
This is correct. But a minimally decent compiler must be able to remove this indirection where possible, like here, and produce efficient code.
Having the optimizer remove indirection is rarely possible in C or C++, due to aliasing.
Mar 02 2011
parent reply dsimcha <dsimcha yahoo.com> writes:
== Quote from Walter Bright (newshound2 digitalmars.com)'s article
 bearophile wrote:
 Bekenn:

 The use of ref introduces a level of indirection.
This is correct. But a minimally decent compiler must be able to remove this indirection where possible, like here, and produce efficient code.
Having the optimizer remove indirection is rarely possible in C or C++, due to aliasing.
I'm sure there are tons of nitty-gritty details in implementing something like this properly, but **in principle**, can't the compiler put a runtime check in for aliasing and select the code path based on whether aliasing is present or not? Essentially, you'd have two generated functions, one that handles the aliasing case and one that handles the no-aliasing case.
Mar 02 2011
parent reply Walter Bright <newshound2 digitalmars.com> writes:
dsimcha wrote:
 == Quote from Walter Bright (newshound2 digitalmars.com)'s article
 bearophile wrote:
 Bekenn:

 The use of ref introduces a level of indirection.
This is correct. But a minimally decent compiler must be able to remove this indirection where possible, like here, and produce efficient code.
Having the optimizer remove indirection is rarely possible in C or C++, due to aliasing.
I'm sure there are tons of nitty-gritty details in implementing something like this properly, but **in principle**, can't the compiler put a runtime check in for aliasing and select the code path based on whether aliasing is present or not? Essentially, you'd have two generated functions, one that handles the aliasing case and one that handles the no-aliasing case.
The check will cost you more than you win! But even a check is rarely even possible. Call any function in C/C++, and the optimizer has to throw in the towel on the values of any indirect references. Even if the optimizer can do interprocedural analysis, the source of that function may not be available to the compiler, or the function may be a virtual call. D has a number of characteristics which can permit much more aggressive optimization, but the opportunity is unrealized.
Mar 02 2011
parent reply Andrei Alexandrescu <SeeWebsiteForEmail erdani.org> writes:
On 3/2/11 3:20 PM, Walter Bright wrote:
 dsimcha wrote:
 == Quote from Walter Bright (newshound2 digitalmars.com)'s article
 bearophile wrote:
 Bekenn:

 The use of ref introduces a level of indirection.
This is correct. But a minimally decent compiler must be able to remove this indirection where possible, like here, and produce efficient code.
Having the optimizer remove indirection is rarely possible in C or C++, due to aliasing.
I'm sure there are tons of nitty-gritty details in implementing something like this properly, but **in principle**, can't the compiler put a runtime check in for aliasing and select the code path based on whether aliasing is present or not? Essentially, you'd have two generated functions, one that handles the aliasing case and one that handles the no-aliasing case.
The check will cost you more than you win!
Often you stand to win a lot, albeit for simple functions (i.e. consider memmove). Andrei
Mar 02 2011
parent reply %u <user pathway.org> writes:
Andrei Alexandrescu Wrote:

 On 3/2/11 3:20 PM, Walter Bright wrote:
 dsimcha wrote:
 == Quote from Walter Bright (newshound2 digitalmars.com)'s article
 bearophile wrote:
 Bekenn:

 The use of ref introduces a level of indirection.
This is correct. But a minimally decent compiler must be able to remove this indirection where possible, like here, and produce efficient code.
Having the optimizer remove indirection is rarely possible in C or C++, due to aliasing.
I'm sure there are tons of nitty-gritty details in implementing something like this properly, but **in principle**, can't the compiler put a runtime check in for aliasing and select the code path based on whether aliasing is present or not? Essentially, you'd have two generated functions, one that handles the aliasing case and one that handles the no-aliasing case.
The check will cost you more than you win!
Often you stand to win a lot, albeit for simple functions (i.e. consider memmove). Andrei
What pisses me off is the Issac Guy doesn't want to support D in the great language benchmark. It's very important utlity for developers. Most coders with C and C++ mentality look the charts and only use the top-2 languages, that is C and C++. If D was there, we could get more users right now, because the optimization benefits make DMD the fastest. Probably even hundreds of enterprises go there to see what language to use. Everyone knows TIOBE is a joke, but this benchmark is probably the most important language benchmark in the web. D is not listed :-( I've been donating few hundred bucks annually to wikipedia, but the deletionist news force me to rethink this. I could donate them to Issac if he just supported our language. Must not be that hard?
Mar 02 2011
next sibling parent reply "Jason E. Aten" <j.e.aten gmail.com> writes:
 What pisses me off is the Issac Guy doesn't want to support D in the great
 language benchmark. It's very important utlity for developers. Most coders
 with C and C++ mentality look the charts and only use the top-2 languages,
 that is C and C++. If D was there, we could get more users right now,
 because the optimization benefits make DMD the fastest. Probably even
 hundreds of enterprises go there to see what language to use. Everyone knows
 TIOBE is a joke, but this benchmark is probably the most important language
 benchmark in the web. D is not listed :-(

 I've been donating few hundred bucks annually to wikipedia, but the
 deletionist news force me to rethink this. I could donate them to Issac if
 he just supported our language. Must not be that hard?
The benchmarks are public so they can be reproduced, right? That's the standard for scientific publication. I can help you reproduce them and put up a webpage if you want to. But I would suggest that it's only really relevant to benchmark against C and C++. The rest is just eye candy. - Jason
Mar 02 2011
parent reply Andrei Alexandrescu <SeeWebsiteForEmail erdani.org> writes:
On 3/2/11 5:41 PM, Jason E. Aten wrote:
     What pisses me off is the Issac Guy doesn't want to support D in the
     great language benchmark. It's very important utlity for developers.
     Most coders with C and C++ mentality look the charts and only use
     the top-2 languages, that is C and C++. If D was there, we could get
     more users right now, because the optimization benefits make DMD the
     fastest. Probably even hundreds of enterprises go there to see what
     language to use. Everyone knows TIOBE is a joke, but this benchmark
     is probably the most important language benchmark in the web. D is
     not listed :-(

     I've been donating few hundred bucks annually to wikipedia, but the
     deletionist news force me to rethink this. I could donate them to
     Issac if he just supported our language. Must not be that hard?


 The benchmarks are public so they can be reproduced, right?  That's the
 standard for scientific publication. I can help you reproduce them and
 put up a webpage if you want to.  But I would suggest that it's only
 really relevant to benchmark against C and C++.  The rest is just eye candy.

 - Jason
I heartily encourage you two to go for this. This has been discussed in the past and my understanding is that Isaac has nothing against D but can't be bothered with a 32-bit setup. Perhaps now with the 64-bit edition maturing, we can look forward to seeing dmd reincluded. Of course, if the benchmarks are already set up properly and working, he'll be much easier compelled. Let me know if you need webspace, I'll be glad to help on d-programming-language.org and/or erdani.com. Andrei
Mar 02 2011
parent reply bearophile <bearophileHUGS lycos.com> writes:
Andrei:

 my understanding is that Isaac has nothing against D but 
 can't be bothered with a 32-bit setup. Perhaps now with the 64-bit 
 edition maturing, we can look forward to seeing dmd reincluded. Of 
 course, if the benchmarks are already set up properly and working, he'll 
 be much easier compelled.
I think your are misunderstanding Isaac. You will probably not see D in that site in a short time. Bye, bearophile
Mar 02 2011
parent reply Andrei Alexandrescu <SeeWebsiteForEmail erdani.org> writes:
On 3/2/11 6:38 PM, bearophile wrote:
 Andrei:

 my understanding is that Isaac has nothing against D but
 can't be bothered with a 32-bit setup. Perhaps now with the 64-bit
 edition maturing, we can look forward to seeing dmd reincluded. Of
 course, if the benchmarks are already set up properly and working, he'll
 be much easier compelled.
I think your are misunderstanding Isaac. You will probably not see D in that site in a short time. Bye, bearophile
Shouldn't even matter, or at most, all the more reason to work on our own benchmarks. Andrei
Mar 02 2011
parent reply Daniel Gibson <metalcaedes gmail.com> writes:
Am 03.03.2011 02:01, schrieb Andrei Alexandrescu:
 On 3/2/11 6:38 PM, bearophile wrote:
 Andrei:

 my understanding is that Isaac has nothing against D but
 can't be bothered with a 32-bit setup. Perhaps now with the 64-bit
 edition maturing, we can look forward to seeing dmd reincluded. Of
 course, if the benchmarks are already set up properly and working, he'll
 be much easier compelled.
I think your are misunderstanding Isaac. You will probably not see D in that site in a short time. Bye, bearophile
Shouldn't even matter, or at most, all the more reason to work on our own benchmarks. Andrei
Well, %u's point was that that shootout could attract developers (enterprises even) to use D - even if they've never heard of D before (or haven't bothered much), if they see it listed on that page and if it performs well they may try D. But having no chance to get onto that page (in the near future) shouldn't prevent us from doing our own benchmarks, of course. It's just a pity that they won't get as much attention when they're not listed there. What were the reasons for not listing D anyway? Cheers, - Daniel
Mar 02 2011
parent reply Andrei Alexandrescu <SeeWebsiteForEmail erdani.org> writes:
On 3/2/11 7:09 PM, Daniel Gibson wrote:
 What were the reasons for not listing D anyway?
I suggest we stop this discussion right here as there's no chance it doesn't turn political. It has occurred a couple of times in the past, with the effect that people wrote email to Isaac asking him the question above in a more or less demanding tone. The fact of the matter is, we can't annoy the man into putting D on the page. What we can do is make D more compelling and more visible by publishing our own benchmarks. This can only have positive effects, among which the possibility that D is added to that site. Andrei
Mar 02 2011
next sibling parent Daniel Gibson <metalcaedes gmail.com> writes:
Am 03.03.2011 02:22, schrieb Andrei Alexandrescu:
 On 3/2/11 7:09 PM, Daniel Gibson wrote:
 What were the reasons for not listing D anyway?
I suggest we stop this discussion right here as there's no chance it doesn't turn political. It has occurred a couple of times in the past, with the effect that people wrote email to Isaac asking him the question above in a more or less demanding tone.
Ok. It wasn't my intention to turn the discussion into a political direction. I thought maybe it were practical issues that could be fixed (or the D community could help), like "no 64bit support" or "setting it up for D (including writing benchmarking code) is much work and he doesn't have the time" or "prefers free compiler for D2" (nowadays GDC could be used) or whatever. I certainly wouldn't demand from Isaac to add D or anything (it's his spare time, after all). Cheers, - Daniel
Mar 02 2011
prev sibling parent Jacob Carlborg <doob me.com> writes:
On 2011-03-03 02:22, Andrei Alexandrescu wrote:
 On 3/2/11 7:09 PM, Daniel Gibson wrote:
 What were the reasons for not listing D anyway?
I suggest we stop this discussion right here as there's no chance it doesn't turn political. It has occurred a couple of times in the past, with the effect that people wrote email to Isaac asking him the question above in a more or less demanding tone. The fact of the matter is, we can't annoy the man into putting D on the page. What we can do is make D more compelling and more visible by publishing our own benchmarks. This can only have positive effects, among which the possibility that D is added to that site. Andrei
How about we do our own benchmarks and perhaps Isaac is willing to put a link to the D benchmarks on his site. -- /Jacob Carlborg
Mar 03 2011
prev sibling parent reply Thomas Mader <thomas.mader gmail.com> writes:
Am 2011-03-03 00:18, schrieb %u:
 What pisses me off is the Issac Guy doesn't want to support D in the great
language benchmark. It's very important utlity for developers. Most coders with
C and C++ mentality look the charts and only use the top-2 languages, that is C
and C++. If D was there, we could get more users right now, because the
optimization benefits make DMD the fastest. Probably even hundreds of
enterprises go there to see what language to use. Everyone knows TIOBE is a
joke, but this benchmark is probably the most important language benchmark in
the web. D is not listed :-(

 I've been donating few hundred bucks annually to wikipedia, but the
deletionist news force me to rethink this. I could donate them to Issac if he
just supported our language. Must not be that hard?
You speak about http://shootout.alioth.debian.org/ right? They had D listed but I don't know why they removed it. See http://replay.waybackmachine.org/20080409212431/http://shootout.alioth.debian.org/ And D is listed on http://www.tiobe.com/index.php/content/paperinfo/tpci/index.html it's just not in the top 20 list. Thomas
Mar 04 2011
parent reply Isaac Gouy <igouy2 yahoo.com> writes:
== Quote from Thomas Mader (thomas.mader gmail.com)'s article

 You speak about http://shootout.alioth.debian.org/ right? They had D
 listed but I don't know why they removed it.
That's been answered many times - http://www.reddit.com/r/programming/comments/ckxjv/d_an_up_and_coming_embedded_software_language/c0u7uv8
Mar 04 2011
next sibling parent reply uri <fun stuff.org> writes:
Isaac Gouy Wrote:

 == Quote from Thomas Mader (thomas.mader gmail.com)'s article
 
 You speak about http://shootout.alioth.debian.org/ right? They had D
 listed but I don't know why they removed it.
That's been answered many times - http://www.reddit.com/r/programming/comments/ckxjv/d_an_up_and_coming_embedded_software_language/c0u7uv8
Maybe if we push it enough, he will find time and motivation some day <prays>.
Mar 04 2011
parent reply Jonathan M Davis <jmdavisProg gmx.com> writes:
On Friday 04 March 2011 19:51:04 uri wrote:
 Isaac Gouy Wrote:
 == Quote from Thomas Mader (thomas.mader gmail.com)'s article
 
 You speak about http://shootout.alioth.debian.org/ right? They had D
 listed but I don't know why they removed it.
That's been answered many times - http://www.reddit.com/r/programming/comments/ckxjv/d_an_up_and_coming_emb edded_software_language/c0u7uv8
Maybe if we push it enough, he will find time and motivation some day <prays>.
He's been pushed too much already. Every time this comes up, someone complains about it, and likely someone bugs him directly about it. I get the impression that he's a bit fed up with it. He's even come to this list directly before (IIRC to say that he wouldn't take donations), in spite of the fact that as far as I know, he doesn't use D. He'll put D back if and when he puts D back. Until then, let's just leave him alone. - Jonathan M Davis
Mar 04 2011
parent reply Daniel Gibson <metalcaedes gmail.com> writes:
Am 05.03.2011 05:35, schrieb Jonathan M Davis:
 On Friday 04 March 2011 19:51:04 uri wrote:
 Isaac Gouy Wrote:
 == Quote from Thomas Mader (thomas.mader gmail.com)'s article

 You speak about http://shootout.alioth.debian.org/ right? They had D
 listed but I don't know why they removed it.
That's been answered many times - http://www.reddit.com/r/programming/comments/ckxjv/d_an_up_and_coming_emb edded_software_language/c0u7uv8
Maybe if we push it enough, he will find time and motivation some day <prays>.
He's been pushed too much already. Every time this comes up, someone complains about it, and likely someone bugs him directly about it. I get the impression that he's a bit fed up with it. He's even come to this list directly before (IIRC to say that he wouldn't take donations), in spite of the fact that as far as I know, he doesn't use D. He'll put D back if and when he puts D back. Until then, let's just leave him alone. - Jonathan M Davis
In fact *he* just replied here, you're even quoting him ;-)
Mar 04 2011
parent Jonathan M Davis <jmdavisProg gmx.com> writes:
On Friday 04 March 2011 20:50:18 Daniel Gibson wrote:
 Am 05.03.2011 05:35, schrieb Jonathan M Davis:
 On Friday 04 March 2011 19:51:04 uri wrote:
 Isaac Gouy Wrote:
 == Quote from Thomas Mader (thomas.mader gmail.com)'s article
 
 You speak about http://shootout.alioth.debian.org/ right? They had D
 listed but I don't know why they removed it.
That's been answered many times - http://www.reddit.com/r/programming/comments/ckxjv/d_an_up_and_coming_e mb edded_software_language/c0u7uv8
Maybe if we push it enough, he will find time and motivation some day <prays>.
He's been pushed too much already. Every time this comes up, someone complains about it, and likely someone bugs him directly about it. I get the impression that he's a bit fed up with it. He's even come to this list directly before (IIRC to say that he wouldn't take donations), in spite of the fact that as far as I know, he doesn't use D. He'll put D back if and when he puts D back. Until then, let's just leave him alone. - Jonathan M Davis
In fact *he* just replied here, you're even quoting him ;-)
LOL. I need to pay more attention. - Jonathan M Davis
Mar 04 2011
prev sibling parent reply Andrei Alexandrescu <SeeWebsiteForEmail erdani.org> writes:
On 3/4/11 9:25 PM, Isaac Gouy wrote:
 == Quote from Thomas Mader (thomas.mader gmail.com)'s article

 You speak about http://shootout.alioth.debian.org/ right? They had D
 listed but I don't know why they removed it.
That's been answered many times - http://www.reddit.com/r/programming/comments/ckxjv/d_an_up_and_coming_embedded_software_language/c0u7uv8
Hi Isaac. Heh, so I remembered correctly. We need to save this link to stem future debates. We could use the energy thus saved for working on the benchmarks themselves. Andrei
Mar 05 2011
parent Isaac Gouy <igouy2 yahoo.com> writes:
== Quote from Andrei Alexandrescu (SeeWebsiteForEmail erdani.org)'s article

 Hi Isaac. Heh, so I remembered correctly. We need to save this link to
 stem future debates. We could use the energy thus saved for working on
 the benchmarks themselves.
Here's the last time I posted that link to this list http://www.digitalmars.com/pnews/read.php?server=news.digitalmars.com&group=digitalmars.D&artnum=120839 Here's the start of that thread http://www.digitalmars.com/pnews/read.php?server=news.digitalmars.com&group=digitalmars.D&artnum=120760 A more generic version of the explanation is shown on the Help page http://shootout.alioth.debian.org/help.php#removed
Mar 05 2011
prev sibling parent Trass3r <un known.com> writes:
 The use of ref introduces a level of indirection.  I suspect the writer  
 was trying to avoid copying array elements -- unnecessary, since  
 vector_t was defined as a dynamic array, where only the bounds are  
 passed.
Yeah I overlooked that, I always think of a struct when thinking about vectors.
Mar 02 2011