Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re^2: a large text file into hash

by perl_lover_always (Acolyte)
on Jan 28, 2011 at 10:37 UTC ( #884779=note: print w/replies, xml ) Need Help??


in reply to Re: a large text file into hash
in thread Reaped: a large text file into hash

Thanks, I'm trying to use your suggested method! the first step created a 18 GB file and sorting it takes lots of time! I could finally sort it and I'm now going to the third step which is creating the last file of $ngram: @line_number. and try to see how can I access it using Search::Dict.
my main usage is that I can have two big files in that way and then calculate some statistics such as Mutual Information from those big files. so as long as I can have the line numbers of each n-gram for both files I try to see how to handle it using search::dict.

Replies are listed 'Best First'.
Re^3: a large text file into hash
by tilly (Archbishop) on Jan 28, 2011 at 16:55 UTC
    Let's see, 18 GB, with a billion rows, so let's say 30 passes, each of which has to both read and write, streaming data at 50 MB/sec takes about 6 hours. It should not be doing all of those passes to disk. Your disk drive is likely to be faster than that. But in any case that is longer than I thought it would take. Sorry.

    The last step should make the file much smaller. How much smaller depends on your data.

    Anyways back to Search::Dict, it works by doing a binary search for the n-gram you are looking up. So you can give it the n-gram and it will find the line number for you. However it is a binary search. If you have a billion rows, it has to do 30 lookups. Some of those will be cached, but a lot will be seeks. Remember that seeks take about 0.005 seconds on average. So if 20 of those are seeks, that is 0.1 seconds. Doesn't sound like much, until you consider that 100,000,000 of them will take 115 days.

    By contrast 100 million 50 byte rows is 5 GB. If you stream data at 50 MB/second (current drives tend to be faster than that, your code may be slower), then you'll need under 2 minutes to stream through that file.

    If you have two of these files, both in sorted form, it really, really makes sense to read them both and have some logic to advance in parallel. Trust me on this.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://884779]
help
Chatterbox?
[davido]: Using the -i switch causes Perl to rename the input file, read from it, and write to a file using the original file's name. If there's an extension provided, as in -i.bak, it's easy to see where the input file is. Where is the input file temporarily....
[davido]: placed if there is no extension provided to the -i switch?
[davido]: Nevermind, found the answer.
[davido]: If no extension is supplied, and your system supports it, the original file is kept open without a name while the output is redirected to a new file with the original filename. When perl exits, cleanly or not, the original file is unlinked.
[haukex]: doc says "If no extension is supplied, and your system supports it, the original file is kept open without a name ..."

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (13)
As of 2017-09-22 14:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    During the recent solar eclipse, I:









    Results (264 votes). Check out past polls.

    Notices?