a | b | |
---|
| 0 | + | <?php |
---|
| 0 | + | |
---|
| 0 | + | /** |
---|
| 0 | + | * Simple speed tester |
---|
| 0 | + | */ |
---|
| 0 | + | class SpeedTest |
---|
| 0 | + | { |
---|
| 0 | + | protected $safe = true; |
---|
| 0 | + | |
---|
| 0 | + | public function run() |
---|
| 0 | + | { |
---|
| 0 | + | $conn = new Mongo(); |
---|
| 0 | + | $collection = $conn->speedtest->coll; |
---|
| 0 | + | |
---|
| 0 | + | $counter = 0; |
---|
| 0 | + | |
---|
| 0 | + | $start = microtime(true); |
---|
| 0 | + | $this->log("Time:\t" . $start); |
---|
| 0 | + | |
---|
| 0 | + | while ($counter++ < 1000000) |
---|
| 0 | + | { |
---|
| 0 | + | $collection->insert(array('counter' => $counter), array('safe' => $this->safe)); |
---|
| 0 | + | } |
---|
| 0 | + | |
---|
| 0 | + | $end = microtime(true); |
---|
| 0 | + | $this->log("Start:\t" . $start); |
---|
| 0 | + | $this->log("End:\t" . $end); |
---|
| 0 | + | $this->log("Diff:\t" . ($end - $start)); |
---|
| 0 | + | $this->log("Avg:\t" . number_format($counter / ($end - $start), 2) . "/s"); |
---|
| 0 | + | } |
---|
| 0 | + | |
---|
| 0 | + | protected function log($str) |
---|
| 0 | + | { |
---|
| 0 | + | echo "{$str}\n"; |
---|
| 0 | + | } |
---|
| 0 | + | } |
---|
| 0 | + | |
---|
| 0 | + | $test = new SpeedTest(); |
---|
| 0 | + | $test->run(); |
---|
... | |
---|