Last active
December 12, 2015 02:08
-
-
Save nickl-/4696036 to your computer and use it in GitHub Desktop.
PHP optimized strtotime() for 24hr time stnings
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Optimized strtotime function. | |
* For turning 24hr time in the form HH:MM:SS into its equivalent | |
* epoch time. | |
* | |
* Returns the same result as strtotime but instead of 0m29.337s | |
* for 1 million records it only takes 0m15.243s or a whopping | |
* 192% performance boost. | |
* | |
* @param $time string 24hr formatted time | |
* @return int unix epoch time equivalent | |
*/ | |
function time_strtotime($time) { | |
$t = explode(':', $time); | |
return ($t[0] * 3600) + ($t[1] * 60) + $t[2] + 1359756000; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Benchmarks 1 000 000 iterations