我在 php 中分析我的代码。问题是关于下一个功能:
// returns true if edge exists in the tree
protected function edgeExist( $srcNodeId, $firstToken ) {
$result = array_key_exists( $srcNodeId, $this->edges )
&& array_key_exists( $firstToken, $this->edges[$srcNodeId]);
return $result;
}
根据分析器,函数edgeExist消耗大约 10% 的运行时间,但函数array_key_exists消耗大约 0.2% 的运行时间。为什么函数edgeExist消耗这么多?