Prev: FAQ 4.74 How do I print out or copy a recursive data structure?
Next: Where to get the document for a library function in command line (linux)?
From: Jorge on 20 May 2010 17:44 Yeah Uri and J gave the program a good going-over so I have plenty to look at there and now I can add your pointers to the list. You mention one very good point that should have been obvious yet it completely got past me ... that beinging I am searching every file for each single pattern where I should be looking at each file only once for all patterns. Ihanks again, Jorge On May 20, 2:30 pm, Jim Gibson <jimsgib...(a)gmail.com> wrote: > In article > <6bf31a76-1cd6-48be-8bea-a91b1c6b8...(a)y21g2000vba.googlegroups.com>, > > > > > > Jorge <awks...(a)yahoo.com> wrote: > > I have a Linux directory full of shell scripts (~100 scripts with > > average > > size of ~60 lines) with many of them calling other scripts as > > depencencies. > > > Not being the author of the scripts and with the immediate need to > > become familiar with > > the overall scope of this script directory, I needed to create a cross- > > reference chart > > that shows what script depends on what other script. > > > My Perl script (below) works in terms of doing what I need, however, > > IMO, it appears to run a bit slow. I timed it at ~3.5 sec. Possibly > > that is it's max performance but something tells me (from other Perl > > script experiences) this one just isn't up to speed. > > > I would appreciate any ideas or comments. > > > Thanks, Jorge > > Uri and J. have given you thorough critiques of your posted program. I > can only add a few additional suggestions. > > Concerning speedup, you have implemented an O(N**2) algorithm. You are > reading each of N files N-1 times, looking for a different script name > each time you read each file. You should read each file only once, and > look for all of your script names in each line. You shouldn't exclude > the script your are reading from this search, since scripts can call > themselves. I would also not look in comments, since it is very common > to put script names in comments, and you don't want those. > > For how to search for many things at once, see the advice in 'perldoc > -q many' "How do I efficiently match many regular expressions at once?" > > You are concatenating the directory name and file name into a path, > then taking many steps to strip the directory name from the path to > retrieve the file name. Don't bother, since you are only working in one > directory and the $dir variable only contains one value. Add $dir to > the open statement or a temp variable: > > my $filename = "$dir/$scripts"; > open( my $f, '<', $filename ) ... > > Then you don't need the @paths array at all. > > [program snipped] > > -- > Jim Gibson- Hide quoted text - > > - Show quoted text -
From: Tad McClellan on 20 May 2010 21:11 Jorge <awkster(a)yahoo.com> wrote: > Yeah Uri and J gave the program a good going-over so I have plenty to > look at there and now I can add your pointers to the list. [ snip TOFU. Please stop doing that! ] TOFU is "Top Over Fullquote Under" also known as "top posting". You were asked nicely (twice!) to stop doing that years ago, yet you continue. I hereby banish you to perpetual invisibility! *plonk* -- Tad McClellan email: perl -le "print scalar reverse qq/moc.liamg\100cm.j.dat/" The above message is a Usenet post. I don't recall having given anyone permission to use it on a Web site.
From: bugbear on 21 May 2010 04:01 Jorge wrote: > I have a Linux directory full of shell scripts (~100 scripts with > average > size of ~60 lines) with many of them calling other scripts as > depencencies. > > Not being the author of the scripts and with the immediate need to > become familiar with > the overall scope of this script directory, I needed to create a cross- > reference chart > that shows what script depends on what other script. > > My Perl script (below) works in terms of doing what I need, however, > IMO, it appears to run a bit slow. I timed it at ~3.5 sec. Possibly > that is it's max performance but something tells me (from other Perl > script experiences) this one just isn't up to speed. > > I would appreciate any ideas or comments. This is a run-once script. Any time spent optimising it (e.g. 10 minutes) is a net loss to you of ten minutes, bar what ever time your optimisation saves from 3.5 seconds. 10 minutes then. BugBear
From: Jorge on 21 May 2010 12:05 On May 20, 6:11 pm, Tad McClellan <ta...(a)seesig.invalid> wrote: > Jorge <awks...(a)yahoo.com> wrote: > > Yeah Uri and J gave the program a good going-over so I have plenty to > > look at there and now I can add your pointers to the list. > > [ snip TOFU. Please stop doing that! ] > > TOFU is "Top Over Fullquote Under" also known as "top posting". > > You were asked nicely (twice!) to stop doing that years ago, > yet you continue. > > I hereby banish you to perpetual invisibility! > > *plonk* > > -- > Tad McClellan > email: perl -le "print scalar reverse qq/moc.liamg\100cm.j.dat/" > The above message is a Usenet post. > I don't recall having given anyone permission to use it on a Web site. Yes I was warned (and IMO not in a nice way) but it has been 3 years since I posted and simply had forgotten about that incident. Sometimes sh*t happens. I will make every effort not to do it again.
From: Jorge on 21 May 2010 12:10
On May 21, 1:01 am, bugbear <bugbear(a)trim_papermule.co.uk_trim> wrote: > Jorge wrote: > > I have a Linux directory full of shell scripts (~100 scripts with > > average > > size of ~60 lines) with many of them calling other scripts as > > depencencies. > > > Not being the author of the scripts and with the immediate need to > > become familiar with > > the overall scope of this script directory, I needed to create a cross- > > reference chart > > that shows what script depends on what other script. > > > My Perl script (below) works in terms of doing what I need, however, > > IMO, it appears to run a bit slow. I timed it at ~3.5 sec. Possibly > > that is it's max performance but something tells me (from other Perl > > script experiences) this one just isn't up to speed. > > > I would appreciate any ideas or comments. > > This is a run-once script. Any time spent optimising > it (e.g. 10 minutes) is a net loss to you of ten minutes, > bar what ever time your optimisation saves from 3.5 seconds. > > 10 minutes then. > > BugBear- Hide quoted text - > > - Show quoted text - Point taken. I probably should have pointed out that the focus of my interest in the program execution speed is not for just this one-time script. Certainly you (and others) are spot on that 3 seconds is of little consequence. However, for future use, I.E., when the day comes that I have to deal with data 100x the size of this data I want to be using the most efficient method(s). Thanks, Jorge |