我有一项任务是将100 000条记录多维数组与自身进行比较。 数组的结构是:
array(
['webpage_url'] => array(
2174418388,
1751917480,
2104295597
... up to 2000 crc32 hashes
)
)
我使用的简单代码是:
$pages = array_keys($this->_pageShingls);
foreach ($pages as $firstPage) {
$firstShingles = $this->_pageShingls[$firstPage];
foreach ($pages as $secondPage) {
if ($secondPage !== $firstPage) {
foreach ($this->_pageShingls[$secondPage] as $hash => $sh) {
if (isset($firstShingles[$hash])) {
if (!isset($shinglIntersection[$firstPage][$secondPage])) {
$shingleIntersection[$firstPage][$secondPage] = 0;
} else {
++$shingleIntersection[$firstPage][$secondPage];
}
}
}
}
}
}
我的机器上最近一次循环迭代大约需要2秒钟。我必须做10万个!有没有办法更快地完成这项工作?