Of the options you listed, padding all lines to a fixed length or making an index of offsets would almost certainly be the fastest. Since you said you have plenty of disk to burn, padding would probably be the faster of the two, since you'd only have to do one seek per line vs. doing a seek to find the offset in your index file/db and then a second seek in the actual data file, but this would come at the cost of increased preprocessing time since you'd need to make two passes over the data file (one to find the longest line and one to get the data for padding), plus you'd be rewriting the whole thing on the second pass. It sounds like you'll be using it enough for the gains in lookup time to outweigh the extra preprocessing time, though.
And then there's the unlisted option 5: Stuff it into an actual database. They're designed to look up arbitrary records quickly, although that again gets into the question of whether you'll be reusing the same dataset often enough to be worth the time taken to insert and index all the data.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
|
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.