From owner-freebsd-hackers Tue Jan 9 23:16:14 1996 Return-Path: owner-hackers Received: (from root@localhost) by freefall.freebsd.org (8.7.3/8.7.3) id XAA16842 for hackers-outgoing; Tue, 9 Jan 1996 23:16:14 -0800 (PST) Received: from godzilla.zeta.org.au (godzilla.zeta.org.au [203.2.228.19]) by freefall.freebsd.org (8.7.3/8.7.3) with SMTP id XAA16835 for ; Tue, 9 Jan 1996 23:16:03 -0800 (PST) Received: (from bde@localhost) by godzilla.zeta.org.au (8.6.9/8.6.9) id SAA00480; Wed, 10 Jan 1996 18:13:29 +1100 Date: Wed, 10 Jan 1996 18:13:29 +1100 From: Bruce Evans Message-Id: <199601100713.SAA00480@godzilla.zeta.org.au> To: hackers@freebsd.org, wosch@cs.tu-berlin.de Subject: Re: wc(1) Sender: owner-hackers@freebsd.org Precedence: bulk >FreeBSD-2.x wc(1) is slow and ugly. NetBSD-current has the same code >as FreeBSD-1.1.5, faster and cleaner written. I didn't know that 1.1.5 was better. It's surprising how much has changed in 2.x, and how much became worse. >time FreeBSD-2.1/wc /usr/share/dict/words > 234936 234936 2486813 /usr/share/dict/words > 6.96 real 6.48 user 0.40 sys >time FreeBSD-1.1.5/wc /usr/share/dict/words > 234936 234936 2486813 /usr/share/dict/words > 5.72 real 5.19 user 0.45 sys >time FreeBSD-2.1/wc -l < /usr/share/dict/words > 234936 > 6.99 real 6.38 user 0.46 sys >time FreeBSD-1.1.5/wc -l < /usr/share/dict/words > 234936 > 2.97 real 2.50 user 0.42 sys Freshly compiled statically linked wc's only show the 20% unimprovement for plain wc here under -current. wc -l is only 6% slower. -current's ctype functions are slightly better, but still too complicated for gcc to optimize well. gcc fails to optimize: char *p; unsigned char c = *p++; int i = c; if (i < 0 || i & 0x80000000) cant_get_here_so_dont_need_to_test_i(); else foo(); This optimization doesn't apply to wc because wc is broken. It uses `int ch = *p++;' to get a sign extension bug. isspace(ch) causes undefined behaviour if ch is negative and not EOF. The actual behaviour is to slow down wc a little for all characters and a lot for negative characters. Sorry I haven't committed your old speed improvements. I don't think wc is very important except as an example. Bruce