What is more efficient for a PHP variable, $timelimit = 10*60; //10 minutes
or $timelimit = 600; //10 minutes
?
I feel as though $timelimit = 600; //10 minutes
would be more efficient/optimized since I am telling PHP that the $timelimit is 600, and I am not asking it to do any calculations.
Efficient to what?
If readability, 60 * 10 is much more understandable than 600 in terms of timing. For performance, 600 is probably a tiny bit better.
Let's say I want to say one day, I'd write 60 * 60 * 24
. It seems cleanier than 86400
Sometimes, efficiency is the way other people (or you, later) can read your code and do something with it.
# cat test2.php
<?php
$time=microtime();
for($i=0; $i<1000000;$i++){
$t = 60*60*24;
}
echo microtime() - $time . "
";
$time=microtime();
for($i=0; $i<1000000;$i++){
$t = 86400;
}
echo microtime() - $time . "
";
# php test2.php
0.05881
0.042382
Over 1 000 000 tries, you lose 0.016 seconds... This isn't nothing, but it's quite close to nothing. I'd prefer to have a clean code.