If you take a look at the implementation of memmove (grab the std C lib source) you'll see a rather optimized assembly loop which is very smart about doing machine-word aligned moves, and using processor block-copy instructions.  I suspect that is the reason you see the difference.  For smaller data sets, you won't see as much gain, if any, because it can't take advantage of those other semantics to the same degree.<div>
<br></div><div>- Cliff<br><br><div class="gmail_quote">On Sat, Apr 9, 2011 at 10:17 AM, spir <span dir="ltr"><<a href="mailto:denis.spir@gmail.com">denis.spir@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<div class="im">On 04/09/2011 07:08 PM, spir wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Hello,<br>
<br>
To insert of delete an array slice, I tried to use C's memmove, thinking it<br>
would be far faster than "manually" copying bit per bit (by any kind of magic).<br>
But I still wrote a D versions just to check what the actual speed gain is. To<br>
my great surprise, the C-memmove and D-manual versions perform *exactly* at the<br>
same speed (considering measure imprecision).<br>
Note: this remains true when elements are bigger; speed slows down slowly (eg<br>
dchar's take only 1/3 more time).<br>
</blockquote>
<br></div>
Correction: memmove can be from 5 to 10 times faster on big arrays. For instance, with 1_000_000 char array:<div class="im"><br>
<br>
void chrono () {<br>
    char[] s;<br>
    d_time t;<br></div>
    enum N = 100;<br>
<br>
    // C memmove<br>
    s = ("0".mult(1_000_000)).dup;<div class="im"><br>
    t = getUTCtime();<br>
    foreach (_ ; 0..N) {<br>
        s.shiftEndPartC(3,5);<br>
        s[3..5] = "--";<br>
        s.shiftEndPartC(5,3);<br>
    }<br>
    t = getUTCtime() - t;<br>
    writefln("C time: %s", t);<br>
<br>
    // D manual<br></div>
    s = ("0".mult(1_000_000)).dup;<div class="im"><br>
    t = getUTCtime();<br>
    foreach (_ ; 0..N) {<br>
    s.shiftEndPartD(3,5);<br>
    s[3..5] = "--";<br>
    s.shiftEndPartD(5,3);<br>
    }<br>
    t = getUTCtime() - t;<br>
    writefln("D time: %s", t);<br>
}<br>
<br></div><div><div></div><div class="h5">
-- <br>
_________________<br>
vita es estrany<br>
<a href="http://spir.wikidot.com" target="_blank">spir.wikidot.com</a><br>
<br>
</div></div></blockquote></div><br></div>