Replacing C's memcpy with a D implementation

Seb seb at wilzba.ch
Sun Jun 10 14:31:29 UTC 2018


On Sunday, 10 June 2018 at 13:45:54 UTC, Mike Franklin wrote:
> On Sunday, 10 June 2018 at 13:16:21 UTC, Adam D. Ruppe wrote:
>
>> arr1[] = arr2[]; // the compiler makes this memcpy, the 
>> optimzer can further do its magic
>
> void memcpyD()
> {
>     dst = src.dup;
> }
>
> void memcpyD2()
> {
>     dst[] = src[];
> }
>
> -----
> memcpyD: 1 ms, 725 μs, and 1 hnsec
> memcpyD2: 587 μs and 5 hnsecs
> memcpyASM: 119 μs and 5 hnsecs
>
> Still, the ASM version is much faster.
>
> btw, what's the difference between the two.  If you can't tell, 
> I'm actually not a very good D programmer.
>
> Mike

I would increase the test data size, s.t. you get a least a few 
seconds.
Otherwise the benchmarking won't tell you much because it's 
subject to too much randomness.


More information about the Digitalmars-d mailing list