Sanely optimized fizzbuzz

Brian Callahan bcallah at openbsd.org
Sat Oct 30 11:35:10 UTC 2021


On Saturday, 30 October 2021 at 09:51:43 UTC, Elronnd wrote:
> On Saturday, 30 October 2021 at 07:30:26 UTC, Brian Callahan 
> wrote:
>> On my very slow machine, the naive solution in C that you 
>> linked to runs at around 64.5 MB/s.
>>
>> An equally naive version in D runs on the same machine at 
>> around 920 MB/s:
>> [...]
>
> That's doing something completely different.  C is generating 
> _all_ fizzbuzz values up to (some very large number), and 
> printing them out once.  Your code is generating all the 
> fizzbuzz values up to (some rather small number), and then 
> printing them out over and over again; effectively a benchmark 
> of i/o.

My machine doesn't have enough memory to do CTFE for values 
larger than 15000. If it did, then I would have done that. The 
rules do not state that you cannot pre-calculate. On my machine, 
the pre-calculating approach gives a significant throughput 
improvement.


More information about the Digitalmars-d mailing list