PHP的Big-O列表
在使用PHP一段时间之后,我注意到并不是所有内置的PHP函数都能达到预期的速度。考虑函数的这两种可能的实现,该函数使用缓存的素数数组查找数字是否为素数。 //very slow for large $prime_array $prime_array = array( 2, 3, 5, 7, 11, 13, .... 104729, ... ); $result_array = array(); foreach( $prime_array => $number ) { $result_array[$number] = in_array( $number, $large_prime_array ); } //speed is much less dependent on size of $prime_array, and runs much faster. $prime_array => …