From owner-freebsd-hackers Tue May 28 11:08:36 1996 Return-Path: owner-hackers Received: (from root@localhost) by freefall.freebsd.org (8.7.5/8.7.3) id LAA18576 for hackers-outgoing; Tue, 28 May 1996 11:08:36 -0700 (PDT) Received: from phaeton.artisoft.com (phaeton.Artisoft.COM [198.17.250.211]) by freefall.freebsd.org (8.7.5/8.7.3) with SMTP id LAA18528 for ; Tue, 28 May 1996 11:08:14 -0700 (PDT) Received: (from terry@localhost) by phaeton.artisoft.com (8.6.11/8.6.9) id LAA11436; Tue, 28 May 1996 11:05:39 -0700 From: Terry Lambert Message-Id: <199605281805.LAA11436@phaeton.artisoft.com> Subject: Re: strcpy, strcat: not the same look & feel. To: bde@zeta.org.au (Bruce Evans) Date: Tue, 28 May 1996 11:05:39 -0700 (MST) Cc: charnier@lirmm.fr, hackers@FreeBSD.org In-Reply-To: <199605280836.SAA08598@godzilla.zeta.org.au> from "Bruce Evans" at May 28, 96 06:36:08 pm X-Mailer: ELM [version 2.4 PL24] MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: owner-hackers@FreeBSD.org X-Loop: FreeBSD.org Precedence: bulk > >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.