"fgrep" is slow
Guy Harris
guy at sun.uucp
Sat Aug 31 10:17:37 AEST 1985
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;
More information about the Net.bugs.usg
mailing list