What is more efficient for a PHP variable, $timelimit 10*60; or $limit 600;? [closed]

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 . "\n";

$time=microtime();
for($i=0; $i<1000000;$i++){
  $t = 86400;
}
echo microtime() - $time . "\n";


# 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.

Leave a Comment