Re: Tie::File surprise (to me)



In article <tbmoore9-CE1501.13303327032007@xxxxxxxxxxxxxxxx>,
boyd <tbmoore9@xxxxxxxxxxx> wrote:

I probably should have known this, but didn't. In Tie::File, where you
tie an array to a long file, and you want to read backwards from the end
of it ( to look for the most recent lines, for example, in a log file),
it is much faster to address the lines with $index as a negative number,
meaning to search from the end of the array. It takes a while for the
module to find the index = -1, but the subsequent searches on -2, -3,
etc. are much faster than using @#array-1, @#array-2, etc.

This may be optimized in later versions - I am using 0.97 version of
Tie::File.

The times I got were on a log file of 30000 lines or so: (my target
lines were ones that started with /^From: / )

Finding last line index, the first way, took: 1.21123 seconds
Finding the "from" lines, the first way, took: 1.86017 seconds
Finding last line index, the second way, took: 1.01147 seconds
Finding the "from" lines, the second way, took: 0.0000119 seconds

where "first way" is using @#array value and decrementing it,
the "second way" is using -1, -2, ...

Finding the last line is about the same in both cases (varies from run
to run) (I used Time::HiRes to get the times - not as accurate as
Devel::DProf, but easier to use in my script).

But notice the tremendous difference in the time of finding the "from"
lines.

Comments?

Boyd

Ignore this posting - I made a dumb error in my second loop - it was not
really running at all. :-!

Boyd
.



Relevant Pages

  • Re: Tie::File surprise (to me)
    ... b> tie an array to a long file, and you want to read backwards from the end ... b> of it (to look for the most recent lines, for example, in a log file), ... b> meaning to search from the end of the array. ...
    (comp.lang.perl.modules)
  • Re: regExp
    ... > It uses ReadAllto store the entire log file into an array then it uses ... ReadAll() is not suitable for "find" style log parsing because it's ... Of course if it's just a script for Juan to run himself, ...
    (microsoft.public.scripting.wsh)
  • Tie::File surprise (to me)
    ... tie an array to a long file, and you want to read backwards from the end ... meaning to search from the end of the array. ... The times I got were on a log file of 30000 lines or so: ...
    (comp.lang.perl.modules)
  • New to Perl. Need some guidance with what to do..
    ... I have a log file which tracks orders that are placed. ... that order will be given a unique identifier. ... customers decides to change the order, the replaced order will be given a ... Well, I can get the first two ids into the array, but I am not ...
    (comp.lang.perl.misc)
  • Re: annoying dhclient error messages
    ... > connection. ... The problem is that I get the following annoying error ... > bytes at end of array ... into a new log file, and block them from the console. ...
    (freebsd-questions)