optimize the bench average costs stats
This commit is contained in:
parent
9659a920e9
commit
5b058d2a8a
|
|
@ -112,6 +112,7 @@ if ($handle === false) {
|
||||||
}
|
}
|
||||||
|
|
||||||
$count = 0;
|
$count = 0;
|
||||||
|
$costs = 0;
|
||||||
$sTime = XdbSearcher::now();
|
$sTime = XdbSearcher::now();
|
||||||
while (!feof($handle)) {
|
while (!feof($handle)) {
|
||||||
$line = trim(fgets($handle, 1024));
|
$line = trim(fgets($handle, 1024));
|
||||||
|
|
@ -145,7 +146,9 @@ while (!feof($handle)) {
|
||||||
$mip = ($sip + $eip) >> 1;
|
$mip = ($sip + $eip) >> 1;
|
||||||
foreach ([$sip, ($sip + $mip) >> 1, $mip, ($mip + $eip) >> 1, $eip] as $ip) {
|
foreach ([$sip, ($sip + $mip) >> 1, $mip, ($mip + $eip) >> 1, $eip] as $ip) {
|
||||||
try {
|
try {
|
||||||
|
$cTime = XdbSearcher::now();
|
||||||
$region = $searcher->search($ip);
|
$region = $searcher->search($ip);
|
||||||
|
$costs += XdbSearcher::now() - $cTime;
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
printf("failed to search ip `%s`\n", long2ip($ip));
|
printf("failed to search ip `%s`\n", long2ip($ip));
|
||||||
return;
|
return;
|
||||||
|
|
@ -169,6 +172,5 @@ while (!feof($handle)) {
|
||||||
// close the searcher at last
|
// close the searcher at last
|
||||||
fclose($handle);
|
fclose($handle);
|
||||||
$searcher->close();
|
$searcher->close();
|
||||||
$cost = XdbSearcher::now() - $sTime;
|
|
||||||
printf("Bench finished, {cachePolicy: %s, total: %d, took: %ds, cost: %.3f ms/op}\n",
|
printf("Bench finished, {cachePolicy: %s, total: %d, took: %ds, cost: %.3f ms/op}\n",
|
||||||
$cachePolicy, $count, $cost/1000, $cost/$count);
|
$cachePolicy, $count, (XdbSearcher::now() - $sTime)/1000, $costs/$count);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue