5oxfr0SEZBm4CdRGHlnjld changeset

Changeset656463316138 (b)
ParentNone (a)
ab
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();
...
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
40
41
42
--- Revision None
+++ Revision 656463316138
@@ -0,0 +1,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();