Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 10 Jan 1996 18:13:29 +1100
From:      Bruce Evans <bde@zeta.org.au>
To:        hackers@freebsd.org, wosch@cs.tu-berlin.de
Subject:   Re: wc(1)
Message-ID:  <199601100713.SAA00480@godzilla.zeta.org.au>

next in thread | raw e-mail | index | archive | help
>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



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