Reputation: 6903
Using LOOP
for ($i=0; $i < 1000; $i++)
{
echo "<li>content $i</li>";
}
Using INCLUDE
include("file.php");
the file.php contains same content as the loop but it is hard coded or static.
I've tried to run those two different codes on local host and monitor their response time. I can't decide which one to choose because the response time changes over time, some times the LOOP is faster but some time the INCLUDE is faster.
I want to ask your recommendation on which one is best to use.
Upvotes: 0
Views: 144
Reputation: 756
Obviously, directly using the loop would be faster. The reason is that when you use the include function, the php compiler has to make a call to include function and then fetch the file. Although the cost of include function is negligible, ( nearly 100 include will cause a lag of 4 milliseconds , but that's not something to worry about).
In the end it all comes down to individual preferences, as this loop might be having a lot of lines of code in the real world and you might want to keep it in a different file for structural purposes
Read This What's the performance cost of "include" in PHP?
Upvotes: 1