Page 1 of 1

file_get_contents & explode VS file. What is faster?

Posted: Tue Aug 17, 2004 5:08 pm
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

Posted: Tue Aug 17, 2004 5:13 pm
by feyd
try testing it and see..

Posted: Tue Aug 17, 2004 5:20 pm
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

Posted: Tue Aug 17, 2004 5:26 pm
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..