- SQLite3 in php — some notes
- APCu in php — some notes
- php’s microtime() function
php’s microtime( true )
function returns a floating point number of seconds since the UNIX epoch. On my computer each call takes about 200ns. The same is true of the time() and hrtime() functions. hrtime()
is more modern and gives nanosecond resolution, so use it if possible. It’s available in php 7.3 and beyond.
By contrast, microtime( false )
returns seconds / microseconds in an array. Each call takes about 560 nanoseconds. So use microtime( true )
. The results are in a more convenient form and cheaper to retrieve.
hrtime( false )
takes about 240 nanoseconds.
The take-home lesson is that timing an operation takes roughly half a microsecond, taking the start time, then doing the operation, then taking the end time.