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); }
Questions and Comments are Welcome