A Friendly Challenge for D
Vijay Nayar
madric at gmail.com
Tue Oct 16 07:09:05 UTC 2018
On Monday, 15 October 2018 at 22:17:57 UTC, Jabari Zakiya wrote:
>> $ dub build --compiler=ldc2 -b=release && echo "3000000000" |
>> ./twinprimes
>> Enter integer number:
>> threads = 8
>> each thread segment is [1 x 65536] bytes array
>> twinprime candidates = 175324676; resgroups = 1298702
>> each 135 threads has nextp[2 x 5566] array
>> setup time = 1 ms, 864 μs, and 7 hnsecs
>> perform twinprimes ssoz sieve
>> sieve time = 196 ms, 566 μs, and 5 hnsecs
>> last segment = 53518 resgroups; segment slices = 20
>> total twins = 9210144; last twin = 2999999712+/- 1
>> total time = 198 ms, 431 μs, and 2 hnsecs
>>
>> My understanding is that the difference in performance is
>> largely due to slightly better optimization from the LLVM
>> based ldc2 compiler, where I believe Nim is using gcc.
>
> Here's what I get on my system.
>
> $ echo 3_000_000_000 | ./twinprimes_test7yc.0180.gcc821
> Enter integer number: threads = 8
> each thread segment is [1 x 65536] bytes array
> twinprime candidates = 175324676; resgroups = 1298702
> each 135 threads has nextp[2 x 5566] array
> setup time = 0.000 secs
> perform twinprimes ssoz sieve
> sieve time = 0.144 secs
> last segment = 53518 resgroups; segment slices = 20
> total twins = 9210144; last twin = 2999999712+/-1
> total time = 0.144 secs
>
> Could you list your hardware, D ver, compiler specs.
>
> I will run your code on my system with your D version and
> compiler, if I can.
>
> Excellent work!
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
Running the program a bunch of times, I get variable results,
mostly between 195ms and 250ms. Running the Nim version, I also
get variable results, mostly between 230ms and 280ms.
My system is an Alienware 14x R2 from 2012. Specs can be found
here:
https://www.cnet.com/products/alienware-m14xr2-14-core-i7-3630qm-8-gb-ram-750-gb-hdd/specs/
More information about the Digitalmars-d
mailing list