Modern C++ Lamentations

Steven Schveighoffer schveiguy at gmail.com
Mon Dec 31 16:05:07 UTC 2018


On 12/31/18 10:15 AM, Steven Schveighoffer wrote:
> On 12/31/18 8:20 AM, Atila Neves wrote:
>> On Sunday, 30 December 2018 at 22:31:27 UTC, Walter Bright wrote:
>>> On 12/30/2018 5:18 AM, Atila Neves wrote:
>>>> On Saturday, 29 December 2018 at 09:29:30 UTC, Walter Bright wrote:
>>>>> http://aras-p.info/blog/2018/12/28/Modern-C-Lamentations/
>>>>>
>>>>> Time to show off your leet D skilz and see how good we can do it in D!
>>>>
>>>> I'm on it. As I write, I'm timing (compile and run time) several 
>>>> C++, D, and Rust implementations and writing a blog post. I'm only 
>>>> on the 2nd implementation but D is winning... :)
>>>>
>>>> I'm going to shamelessly steal Timon's range code in this thread and 
>>>> the generator one posted on reddit.
>>>
>>> Wow! I'm looking forward to it.
>>
>> Blog:
>>
>> https://atilanevesoncode.wordpress.com/2018/12/31/comparing-pythagorean-triples-in-c-d-and-rust/ 
>>
>>
>> Reddit:
>>
>> https://www.reddit.com/r/programming/comments/ab71ag/comparing_pythagorean_triples_in_c_d_and_rust/ 
>>
>>
>>
>> Hacker news something something dark side.
>>
>>
> 
> I tried the version I came up with with a dedicated looping range 
> (https://run.dlang.io/is/hkqhvZ), cuts the range version down to 550ms 
> (my timings are on my macbook, but my baseline was literally exactly 
> what yours was, 154ms).
> 
> In any case, it does seem like the optimizer/compiler is much better at 
> dealing with nested loops than 3 ranges. This is probably a case where 
> the low level code is so fast (doing 3 multiplications, an addition and 
> an equality check) that the loop processing becomes significant.
> 

And the answer was provided by someone who examined the compiler output:

https://www.reddit.com/r/programming/comments/ab71ag/comparing_pythagorean_triples_in_c_d_and_rust/ecy6rqn/

And it fixes the problem with Timon's D version as well, new time down 
to 172ms (see my reply to that post).

-Steve


More information about the Digitalmars-d mailing list