file_get_contents & explode VS file. What is faster?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
tomfra
Forum Contributor
Posts: 126
Joined: Wed Jun 23, 2004 12:56 pm
Location: Prague, Czech Republic

file_get_contents & explode VS file. What is faster?

Post by tomfra »

If I have a .txt file with one record on each file and want to get the values into array, what is faster?

Get the data through 'file_get_contents' which is fast and explode the string or use 'file' which will transform it into array directly?

What is faster for large number of lines - let's say 5000 or 10000 lines?

Thanks!

Tomas
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

try testing it and see..
tomfra
Forum Contributor
Posts: 126
Joined: Wed Jun 23, 2004 12:56 pm
Location: Prague, Czech Republic

Post by tomfra »

That's what I will probably have to do anyway. I know that 'file_get_contents' is real fast from one comparisor I read a while ago but then the question is how fast string exploding is? Is there somewhere a good function to measure function execution time?

Tomas
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

the older profiling way:

get the current time
run it 100000 times
get the current time
take the difference of the two..

crude, yes, but it mostly works.. although processors with big caches will execute subsequent runs very fast compared to the first run.. soo.. with a grain of salt..
Post Reply