
Perl memory and speed questions (Lots of code)
I have two questions: 1) why is it that perls grep seems to take substantially
longer to execute than if I simply write the text to a file and shell
off a grep against the file, and 2) I have a perl script that uses the
same variables over and over again to read into and process and the process
keeps getting larger and larger (on the order of 8k every 10 seconds).
#1:
The only differences between the memory resident and shelled grep are:
MEMORY RESIDENT VERSION:
$text_line = sprintf ("%s -", $n_file);
$output_this_line = 0;
$totals{$lib_entry} =
$totals{$lib_entry} +
$#grep_out + 1;
if ($summary_only != 1) {
$text_line =
sprintf ("%s %d,",
$text_line,
$#grep_out + 1);
if ($#grep_out >= 0) {
$output_this_line = 1;
}
}
}
if ($summary_only != 1) {
if ($output_this_line == 1) {
printf STDOUT "%s\n",
$text_line;
}
}
undef $text_line;
SHELLED GREP VERSION:
`stripcom $n_file >$$.1.tmp`;
$text_line = sprintf ("%s -", $n_file);
$output_this_line = 0;
$totals{$lib_entry} =
$totals{$lib_entry} +
$#grep_out + 1;
if ($summary_only != 1) {
$text_line =
sprintf ("%s %d,",
$text_line,
$#grep_out + 1);
if (($#grep_out + 1) > 0) {
$output_this_line = 1;
}
}
}
if ($summary_only != 1) {
if ($output_this_line == 1) {
printf STDOUT "%s\n",
$text_line;
}
}
undef $text_line;
It seems to make sense that a memory resident scan of the text would be
faster than to shell off a grep and read a file and then return....BUT
I could be wrong.
#2:
This script is used to scan libraries of "C" code extract the routines
in the library then check source code file and report back the
files which use routines from the libraries. The script will traverse the
directory and search any subdirectories.
#!/usr/bin/perl
$summary_only = 0;
if ($#ARGV < 1) {
printf "usage%d: liblist library_file c-code_file/directory\n", $#ARGV;
exit (0);
Quote:
}
$library_text_line = sprintf ("%s -", "File\\Library Routine");
if (($directory =~ /^-l/) || ($directory =~ /^-L/)) {
if ($#nm_output <= 0) {
die "Invalid library";
}
if (($nm_entry =~ s/^[0-9a-fA-F]+ T _//) &&
($nm_entry =~ s/\n$//)) {
$library_text_line = sprintf ("%s %s,",
$library_text_line, $nm_entry);
}
}
if ($summary_only != 1) {
printf STDOUT "%s\n", $library_text_line;
}
}
elsif (($directory =~ /-s/) || ($directory =~ /-S/)) {
$summary_only = 1;
}
else {
&CHECK_DIR ($directory);
}
Quote:
}
if ($summary_only != 1) {
$text_line = sprintf ("%s -", "Totals");
$text_line = sprintf ("%s %d,", $text_line,
$totals{$lib_entry});
}
printf STDOUT "%s\n", $text_line;
Quote:
}
printf STDOUT "%s = %d\n", $lib_entry, $totals{$lib_entry};
Quote:
}
exit (0);
sub CHECK_DIR {
if (opendir (DIRECTORY, "$directory"))
{
closedir (DIRECTORY);
$n_file = "$directory/$n_file";
if ((-d $n_file)) {
if ($n_file =~ /SCCS/) {
next;
}
if ($n_file =~ /RCS/) {
next;
}
if ($n_file =~ /\.rcs.*/) {
next;
}
if ($n_file =~ /.*OLD/) {
next;
}
if ($n_file =~ /spr/) {
next;
}
&CHECK_DIR ("$n_file");
}
else
{
if (($n_file =~ /.*\.c$/) ||
($n_file =~ /.*\.y$/) ||
($n_file =~ /.*\.l$/) ||
($n_file =~ /.*\.h$/))
{
printf STDERR "working_file = %s\n", $n_file;
`stripcom $n_file >$$.1.tmp`;
$text_line = sprintf ("%s -", $n_file);
$output_this_line = 0;
$totals{$lib_entry} =
$totals{$lib_entry} +
$#grep_out + 1;
if ($summary_only != 1) {
$text_line =
sprintf ("%s %d,",
$text_line,
$#grep_out + 1);
if (($#grep_out + 1) > 0) {
$output_this_line = 1;
}
}
}
if ($summary_only != 1) {
if ($output_this_line == 1) {
printf STDOUT "%s\n",
$text_line;
}
}
undef $text_line;
}
}
}
`/bin/rm -f $$.1.tmp`;
}
Quote:
}
Thanks in advance to anyone who even bothers read all this
Fred
--
Oscar "Fred" DeMartino - J.P.L. (818) 306-6181 J PPP L
4800 Oak Grove Drive, Pas, CA. 91109 MS: 525-3660 J P P L