A Friendly Challenge for D

Jon Degenhardt jond at noreply.com
Tue Oct 16 17:42:27 UTC 2018


On Tuesday, 16 October 2018 at 07:09:05 UTC, Vijay Nayar wrote:
> D has multiple compilers, but for the speed of the finished 
> binary, LDC2 is generally recommended.  I used version 1.11.0.  
> https://github.com/ldc-developers/ldc/releases/tag/v1.11.0
>
> I was using DUB to manage the project, but to build the 
> stand-alone file from the gist link, use this command:  $ ldc2 
> -release -O3 twinprimes_ssoz.d
> And to run it:  $ echo "3000000000" | ./twinprimes_ssoz

It'd be interesting to see if LTO or PGO generated an 
improvement. It looks like it could in this case, as it might 
optimize some of the inner loops. LTO is easy, enable it with:

     -flto=<thin|full> -defaultlib=phobos2-ldc-lto,druntime-ldc-lto

(see: https://github.com/ldc-developers/ldc/releases/tag/v1.9.0). 
I've been using 'thin' on OSX, 'full' on Linux.

PGO is a bit more work, but not too bad. A good primer is here: 
https://johanengelen.github.io/ldc/2016/07/15/Profile-Guided-Optimization-with-LDC.html

--Jon




More information about the Digitalmars-d mailing list