Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.2 9/18/84 SMI; site sun.uucp Path: utzoo!watmath!clyde!burl!ulysses!allegra!mit-eddie!genrad!decvax!decwrl!sun!guy From: guy@sun.uucp (Guy Harris) Newsgroups: net.bugs.usg Subject: "fgrep" is slow Message-ID: <2734@sun.uucp> Date: Fri, 30-Aug-85 20:17:37 EDT Article-I.D.: sun.2734 Posted: Fri Aug 30 20:17:37 1985 Date-Received: Sun, 1-Sep-85 06:02:33 EDT Distribution: net Organization: Sun Microsystems, Inc. Lines: 51 It's slow because it uses a subroutine to perform every(!) character comparison. The 4.2BSD one uses a macro; does V7's also use a macro? Changing it to use a macro makes a major difference (like ~10 CPU seconds on a 200,000 character file - that's ~40% of the CPU time on my Sun). *** fgrep.c.BAK Mon Aug 19 17:02:39 1985 --- fgrep.c Fri Aug 30 16:04:56 1985 *************** *** 39,44 extern char *optarg; extern int optind; main(argc, argv) char **argv; { --- 39,48 ----- extern char *optarg; extern int optind; + /* The following macro was inserted to allow for the "-i" option */ + + #define same(a, b) ((a) == (b) || iflag && ((a) ^ (b)) == ' ' && letter(a) == letter(b)) + main(argc, argv) char **argv; { *************** *** 356,368 } } ! /* The following functions were inserted to allow for the "-i" option */ ! ! same(a, b) ! register int a, b; ! { ! return (a == b || iflag && (a ^ b) == ' ' && letter(a) == letter(b)); ! } letter(c) register int c; --- 360,366 ----- } } ! /* The following function was inserted to allow for the "-i" option */ letter(c) register int c;