Function to print a diamond shape
monarch_dodra via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Tue Apr 22 08:21:35 PDT 2014
On Tuesday, 22 April 2014 at 05:05:30 UTC, Jay Norwood wrote:
> On Monday, 21 April 2014 at 08:26:49 UTC, monarch_dodra wrote:
>> The two "key" points here, first, is to avoid using appender.
>> Second, instead of having two buffer: " " and "******\n",
>> and two do two "slice copies", to only have 1 buffer "
>> *****", and to do 1 slice copy, and a single '\n' write. At
>> this point, I'm not sure how we could be going any faster,
>> short of using alloca...
>>
>> How does this hold up on your environment?
>
> Yes your solution is the fastest yet. Also, its times are
> similar for all three compilers. The range of execution times
> varied for different solutions from over 108 seconds down to 64
> msec.
>
> I see that RefAppender's data() returns the managed array. Can
> write() handle that? It seems that would be more efficient
> than duplicating the character buffer ...
I'm not sure what you mean? "data" returns the managed array, but
no duplication ever actually happens. It's allocated on the GC.
the only thing that is copied is the slice itself.
> or perhaps writing directly to an OutBuffer, and then sending
> that to write() would avoid the duplication?
appender *is* the outbuffer :)
More information about the Digitalmars-d-learn
mailing list