pkedpker Posted June 21, 2009 Share Posted June 21, 2009 my question is there any overhead doing just function calls like this <?php //color $fh = fopen("data/test.txt", 'r'); $data = fread($fh, filesize("data/test.txt")); fclose($fh); compared to <?php //color $data = loadData("test.txt"); function loadData($filename) { $fh = fopen("data/$filename", 'r'); $data = fread($fh, filesize("data/$filename")); fclose($fh); return $data; } since I remember returning something very huge.. like 2GB is kinda bad because it would do a copy of all bytes losing time.. unless its a shared pointer is it? I just want to know if there is any speed loss?.. other then calling functions.. should i rebuilt this function algorithm in every piece of coding i need to load something just so i don't have to return it? Quote Link to comment Share on other sites More sharing options...
corbin Posted June 21, 2009 Share Posted June 21, 2009 Assuming PHP is intelligent enough to return a pointer to the memory allocated for $data it should use about the same amount of memory. Otherwise though, it will use double. I bet that PHP will return a pointer to the previously allocated memory though. Not sure though. Quote Link to comment Share on other sites More sharing options...
pkedpker Posted June 21, 2009 Author Share Posted June 21, 2009 obviously php should be smart to do this.. but I can't just assume I also am very bad at setting up benchmark tests. Hopefully someone will shed more light on this. Quote Link to comment Share on other sites More sharing options...
Ken2k7 Posted June 21, 2009 Share Posted June 21, 2009 From my tests, the execution time between both versions is negligible. Quote Link to comment Share on other sites More sharing options...
pkedpker Posted June 21, 2009 Author Share Posted June 21, 2009 Okay I believe that solved than.. not like I was going to run 2GB files anyways but its always a possibly with the growing in size files. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.