file vs. fgets - performance question

This is a discussion on file vs. fgets - performance question within the PHP Language forums, part of the PHP Programming Forums category; I have a large file that I need to put into an array - but I only need the last hundred ...


Go Back   Usenet Forums > PHP Programming Forums > PHP Language

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 10-12-2004
deko
 
Posts: n/a
Default file vs. fgets - performance question

I have a large file that I need to put into an array - but I only need the
last hundred or so lines. The file is approx. 1100 lines total (20k). Is
it more efficient to use fgets in a situation like this? I'm wondering if
it's quicker to read into the array only the lines I need (fgets), rather
than converting the whole file into an array (file). Or is file quicker
since I don't need fopen?


Reply With Quote
  #2 (permalink)  
Old 10-13-2004
Stefan Hegenbart
 
Posts: n/a
Default Re: file vs. fgets - performance question

deko wrote:
> I have a large file that I need to put into an array - but I only need the
> last hundred or so lines. The file is approx. 1100 lines total (20k). Is
> it more efficient to use fgets in a situation like this? I'm wondering if
> it's quicker to read into the array only the lines I need (fgets), rather
> than converting the whole file into an array (file). Or is file quicker
> since I don't need fopen?
>
>


the usual file handling routines will be used with file() too. the
difference is that you won't have to take care of it.

maybe you should just try both and benchmark them - i think the
fopen-variant with fgets is faster as it is not reading those many lines.

reg.
s.h.

--
"The goal of Computer Science is to build something that will last at
least until we've finished building it." -- unknown
Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 08:56 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0