Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 28 May 1996 11:05:39 -0700 (MST)
From:      Terry Lambert <terry@lambert.org>
To:        bde@zeta.org.au (Bruce Evans)
Cc:        charnier@lirmm.fr, hackers@FreeBSD.org
Subject:   Re: strcpy, strcat: not the same look & feel.
Message-ID:  <199605281805.LAA11436@phaeton.artisoft.com>
In-Reply-To: <199605280836.SAA08598@godzilla.zeta.org.au> from "Bruce Evans" at May 28, 96 06:36:08 pm

next in thread | previous in thread | raw e-mail | index | archive | help
> >Which one is faster, the old version or the one with this patch applied?
> >Libc uses another one (assembler) but this could at least make libkern
> >faster. Or is it even better to use the libc's version? I'm not really sure
> >about my results but it seems that the following patch make strcpy 8% faster
> >(-O0) 6% faster (-O) and 0% faster (-O2) on my i486 according to gprof.
> 
> >...
> >-	for (; *to = *from; ++from, ++to);
> >+	while (*to++ = *from++);
> 
> They are essentially the same, But gcc doesn't recognise this at any
> optimization level, and generates slightly different code that happens
> to be faster or slower depending on the cpu.  I get quite different
> results for one test with a short string (of length 5) on a Pentium:

There is also some conventional wisdom on pre vs. post-incrementing,
which I wasn't going to mention because I was under the impresson
that all modern compilers dealt with it.

Post-increment is generally faster if you have the instruction set for
it; not all systems have the instruction set.

The real fix is to have the compiler Deal With It.  The location and
pre vs. post are commutative.


					Terry Lambert
					terry@lambert.org
---
Any opinions in this posting are my own and not those of my present
or previous employers.



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199605281805.LAA11436>