On 07/19/2016 10:41 AM, deadalnix wrote:
On Tuesday, 19 July 2016 at 10:07:11 UTC, Atila Neves wrote:
On Tuesday, 19 July 2016 at 02:54:37 UTC, Saurabh Das wrote:
Posted on Atila's blog yesterday:
https://atilanevesoncode.wordpress.com/2016/07/18/c-is-not-magically-fast-part-2/
So, about D vs C++ there... last night for reasons I forget I tried
replacing std::string with const char* in the C++ version, and then it
got faster than D. I don't know why.
At first I thought std::string was being copied instead of being
moved, but some static_asserts made me doubt that. Either way, there's
no good reason I can think of for C++ to magically speed up for const
char*. Hmm :(
Atila
What compiler are you using ? If it is LLVM based, could you post IR ?
Also:
if(i < other.i) return -1;
if(i > other.i) return 1;
Should be
(i > other.i) - (i < other.i)
Surprisingly, LLVM was unable to optimize one into the other in my tests.
Additionally, the string may be traversed twice in opCmp. The following
change makes D example faster:
import std.algorithm : cmp;
return cmp(s, other.s);
// return s < other.s
// ? -1
// : (s > other.s ? 1 : 0);
Ali