Prime sieve language race
Bastiaan Veelo
Bastiaan at Veelo.net
Tue Jul 13 22:01:21 UTC 2021
On Tuesday, 13 July 2021 at 21:02:55 UTC, SealabJaster wrote:
> I can assure you it shows `Valid: true` now!
Phew! :-)
> Or maybe I'll update the code slightly to allow both a runtime
> and compile-time set sieve size >:3
That would be nice.
> While the Sieve does do the computations at runtime, the sieve
> size is a compile-time constant, and the buffer is static
> (technically one could argue that it *is* dynamically allocated
> due to being in a class >:D ).
Heh yes. Also, he said something like “as if you would write an
API”. I like templated APIs…
I saw two comments regarding dynamic sieve size. One of them was
an entire stack-based implementation, to which he responded not
seeing a problem with that. Another suggested using `alloca`.
>> 3. Line 23 `// it also allows D to write more "file-portable"
>> code.` Not sure what you mean by this. Worth noting however is
>> that the import only happens iff the template is instantiated,
>> which is nice.
>
> Basically, if you use scoped imports it tends to be a lot
> easier to move a piece of code between different files. A lot
> of the time you can get away with a simple cut+paste and it can
> just work.
Agreed. Thanks.
>> Out of curiosity, do you know how your solution compares with
>> the first one performance wise, roughly?
>
> [1] is for the first solution, and [2] is for the second one.
[….]
> [1] https://pastebin.com/Q0UxibTi
> [2] https://pastebin.com/tmXDwejS
Those are nice improvements! Glad you took the time.
— Bastiaan.
More information about the Digitalmars-d
mailing list