Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: How to improve speed of reading big files

by bv (Friar)
on Sep 17, 2009 at 16:12 UTC ( [id://795921]=note: print w/replies, xml ) Need Help??


in reply to How to improve speed of reading big files

You seem to be using pretty structured data (maybe the wrong word here, sorry), yet only one of your regexps is anchored. If you know the position of certain strings (especially /Running|Dump|FromCB|Update/o), you could gain some speedup by anchoring, even if you have to resort to assigning to pos.

Another thing would be to precompile or use the /o modifier on your substitutions, since &filterLog gets called so often.

print pack("A25",pack("V*",map{1919242272+$_}(34481450,-49737472,6228,0,-285028276,6979,-1380265972)))

Replies are listed 'Best First'.
Re^2: How to improve speed of reading big files
by korlaz (Novice) on Sep 18, 2009 at 07:57 UTC
    Could you explain me the "pos" trick ?

      From the pos documentation:

      pos directly accesses the location used by the regexp engine to store the offset, so assigning to pos will change that offset, and so will also influence the \G zero-width assertion in regular expressions.

      So if we know that we have fixed-width data and we only want to match "foo", "ding", or "widget" starting at the 10th character of the string, we can assign to pos($string) to set the "last matched position" to something other than 0, and then use the \G anchor (technically a zero-width assertion, like ^ and $) like so:

      while(<DATA>) { pos() = 10; print if /\G(?:foo|ding|widget)/o; } __DATA__ 3.14 PI foo 6.28 2PI ding 42 LUE answer 7 LUK superstition 87.32 UNK widget

      This code prints lines 1, 2, and 5

      print pack("A25",pack("V*",map{1919242272+$_}(34481450,-49737472,6228,0,-285028276,6979,-1380265972)))

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://795921]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (6)
As of 2024-04-25 08:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found