Revision 656463316138 () - Diff

Link to this snippet: https://friendpaste.com/5oxfr0SEZBm4CdRGHlnjld
Embed:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
<?php

/**
* Simple speed tester
*/
class SpeedTest
{
protected $safe = true;

public function run()
{
$conn = new Mongo();
$collection = $conn->speedtest->coll;

$counter = 0;

$start = microtime(true);
$this->log("Time:\t" . $start);

while ($counter++ < 1000000)
{
$collection->insert(array('counter' => $counter), array('safe' => $this->safe));
}

$end = microtime(true);
$this->log("Start:\t" . $start);
$this->log("End:\t" . $end);
$this->log("Diff:\t" . ($end - $start));
$this->log("Avg:\t" . number_format($counter / ($end - $start), 2) . "/s");
}

protected function log($str)
{
echo "{$str}\n";
}
}

$test = new SpeedTest();
$test->run();