PHP strftime() is Faster Than date() in PHP 7

After running several benchmark tests, I find that the PHP strftime() is faster than date(). I tested each one creating the same datetime string in this format: ‘YYYY-MM-DD HH:MM’.

The test iterates 100000 times over each function. I repeated this test several times. Each time, I alternated which function ran first. Here are the benchmark speed test results. The average execution times are for running 100000 times, and they are in milliseconds.

PHP ‘strftime()’ versus ‘date()’

Average execution time for strftime(): 255.05 ms
Average execution time for my_date(): 300.25 ms


This was using PHP version 7.3.16. To run this benchmark test, I used my benchmarking template and the following functions:

function my_strftime(){
    $mktime = mktime(2,0,0,03,27,1921);
    return strftime("%Y-%m-%d %H:%M", $mktime);
function my_date(){
    $mktime = mktime(2,0,0,03,27,1921);
    return date('Y-m-d H:i', $mktime);

See more: , ,


Questions and Comments are Welcome

Your email address will not be published. All comments will be moderated.

Please wrap code in "code" bracket tags like this: