This is the mail archive of the guile@sourceware.cygnus.com mailing list for the Guile project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: Using memcpy instead of `*dst++ = *src++'


On Mon, 5 Jun 2000, Dale P. Smith wrote:

> Does it make any sense to change scm_makfromstr from:
> 
> SCM 
> scm_makfromstr (const char *src, scm_sizet len, int slots)
> {
>   SCM s = scm_makstr (len, slots);
>   char *dst = SCM_CHARS (s);
> 
>   while (len--)
>     *dst++ = *src++;
>   return s;
> }
> 
> to something like:
> 
> SCM 
> scm_makfromstr (const char *src, scm_sizet len, int slots)
> {
>   SCM s = scm_makstr (len, slots);
> 
>   memcpy (SCM_CHARS (s), src, len);
>   return s;
> }
> 
> ???  I would guess that for small strings the overhead of a function call might slow things down.  But memcpy is supposedly tuned for better performance that a simple char by char copy.  I got a
> slight improvement, but it was in the system, not user timings. ???  It's probably very architecture and C library dependent.

I have done a similar change with the continuations:  The stack copying
functions now use memcpy.  This brought an impressive speedup on sparc
solaris, but was not noticeable on my pentium linux machine.

However, for the continuations there's a lot of stuff to be copied, while
the typical strings may be quite short.  It could be interesting to check
whether the length is larger than a certain threshold and then either call
memcpy or not.  The advantage is, that for short strings the penalty is
just a comparison of the length with the threshold plus a branch, but not
the procedure call overhead.  It may be, though, that memcpy is a macro
which does exactly this:  Check the length and either perform inline
copying or call a function.  I have not checked this, though.

Best regards
Dirk


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]