0

Trying to test how long mongo takes to retrieve each document.

However, system() prints the result to screen and I think that may slow down the process.

How could I supress it from printing to screen?

<?php
$m = new MongoClient();
$db = $m->selectDB("test");
$collection = new MongoCollection($db, "fakestat");
for($i=0;$i<1000;$i++){
        $index[]=rand(1,432050);
}
$fp = fopen('logTime.txt','w');
fwrite($fp, "startTimeSec\t startTimeNanoSec\t endTimeSec\t endTimeNanoSec\n");

foreach($index as $val) {
        $startTime = system("date +%s'\t'%N");
        $results[] = $collection->findOne(array("capture"=>"$val"));
        $endTime = system("date +%s'\t'%N");
        fwrite($fp, sprintf("%s\t %s\n", $startTime, $endTime));
}
fclose($fp);
$m->close();
?>

Update: Using exec() and it seems to be work abeit still rather slow.

4

1 に答える 1

1

2つのオプション:

  1. 代わりにshell_execを使用してくださいsystem

    $startTime = shell_exec("date +%s'\t'%N");
    
  2. 代わりにマイクロタイムを使用してください。

    microtime —現在のUnixタイムスタンプをマイクロ秒で返します

    $startTime = microtime();
    
于 2013-02-18T02:34:08.247 に答える