Talk About Network



Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Perl Beginners > Re: opening a b...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 1 Topic 10971 of 11065
Post > Topic >>

Re: opening a big file

by chas.owens@[EMAIL PROTECTED] (Chas. Owens) Apr 21, 2008 at 01:18 PM

On Mon, Apr 21, 2008 at 11:18 AM, Gunnar Hjalmarsson <noreply@[EMAIL PROTECTED]
>
wrote:
> Mr. Shawn H. Corey wrote:
>
> > The fastest way to do this is to read every line into Perl and
disregard
> everything not relevant.
> >
>
>  Don't think so.
>
>  I did a benchmark on a text file with 100,000 lines, where I'm actually
> only interested in the 5 last lines. Except for Tie::File, which proved
to
> be awfully slow, reading and testing every line against a regex took
> hundreds of times longer time compared to seek() or File::ReadBackwards.
> Please see below.
snip

It is even worse than the benchmarks would lead you to believe.
Unless you setup your file system and kernel (in)correctly every read
from the file after the first benefits from the cache, so the cost of
reading the whole file is not accurately reflected in your benchmark
(which is why I didn't bother with one).  Also, they have different
orders of growth.  Reading the whole file will get slower as the file
size gets bigger, but the method used by File::ReadBackwards will slow
down a little and then stay (relatively*) constant.

* The cost to walk the inode tree is O(log n), so it grows, but very
slowly

-- 
Chas. Owens
wonkden.net
The most important skill a programmer can have is the ability to read.




 1 Posts in Topic:
Re: opening a big file
chas.owens@[EMAIL PROTECT  2008-04-21 13:18:37 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Thu May 15 0:18:55 CDT 2008.