채택완료

이 코드를 최적화 할수있을까요?

2023-06-26 (월) 02:46:19 2,670
Copy
// 마이크로 타임을 얻어 계산 형식으로 만듦
function get_microtime()
{
    list($usec, $sec) = explode(" ",microtime());
    return ((float)$usec + (float)$sec);
}

php 5.2.17 이상에서 동작하면 됩니다. 

불필요한 로직을 최적화하고 저 한 줄 주석 대신 phpdoc으로 어떻게 깔끔하게 정리할 수 있을까요?

|

답변 2개 / 댓글 1개

채택된 답변
+20 포인트
Copy
return microtime(true);
Copy
/**
 * Get the current Unix timestamp with microseconds.
 *
 * @return float The current Unix timestamp with microseconds.
 */
function get_microtime(): float
{
    list($usec, $sec) = explode(" ", microtime());
    return (float)$usec + (float)$sec;
}

답변에 대한 댓글 1개

코드는 더이상 줄일 수 없나요?

답변을 작성하려면 로그인이 필요합니다.