LonghornPHP 2026

Voting

: max(seven, seven)?
(Example: nine)

The Note You're Voting On

unixtojd at isslow dot com
2 years ago
unixtojd is slow.
Direct arithmetics calculations are faster and still coherent with original unixtojd.

Feel free to add a test on $timestamp to set it to time() when $timestamp is null.

function fast_unixtojd($timestamp){
    return intval($timestamp / 86400 + 2440588);
}

$time = time();
$t_unixtojd = 0;
$t_fast_unixtojd = 0;
for ($t = $time - 240 * 3600; $t < $time; $t++) {
    $time1 = microtime(true);
    $a = unixtojd($t);
    $time2 = microtime(true);
    $b = fast_unixtojd($t);
    $time3 = microtime(true);
    if ($a != $b) {
        echo "$a $b $t\n";
        break;
    }
    $t_unixtojd += $time2 - $time1;
    $t_fast_unixtojd += $time3 - $time2;
}
echo "unixtojd: $t_unixtojd sec\nfast_unixtojd: $t_fast_unixtojd sec\n";

unixtojd: 0.42854166030884 sec
fast_unixtojd: 0.13218021392822 sec

<< Back to user notes page

To Top