File: performance.php

package info (click to toggle)
php-mongo 1.4.5-1~bpo70%2B1
  • links: PTS
  • area: main
  • in suites: wheezy-backports
  • size: 9,828 kB
  • sloc: ansic: 13,275; xml: 1,702; php: 1,625; pascal: 255; makefile: 106; sh: 27
file content (280 lines) | stat: -rw-r--r-- 10,464 bytes parent folder | download | duplicates (2)
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
<?php

define('PER_TRIAL', 5000);
define('BATCH_SIZE', 100);

$m  = new Mongo();
$db = $m->selectDB("test");

function micro_time()
{
  list($usec, $sec) = explode(" ", microtime());
  return (float)$usec + (float)$sec;
}

function none($c, $obj)
{
  $c->drop();
  go($c, $obj);

  $c->drop();
  go_find_one($c, $obj);
}

function index($c, $obj)
{
  $c->drop();
  $c->ensureIndex("x");
  go($c, $obj);

  $c->drop();
  $c->ensureIndex("x");
  go_find_one($c, $obj);
}

function batch($c, $obj)
{
  echo "{batch insert} $c\n";

  $c->drop();

  $batches = array();
  for($i=0;$i < PER_TRIAL;$i++){
    $batch = array();
    for($j=0;$j<BATCH_SIZE;$j++){
      $obj["x"]=$i;
      $batch[] = $obj;
      $i++;
    }
    $batches[] = $batch;
  }
  $num_batches = count($batches);

  $start = micro_time();
  for($i=0;$i < $num_batches;$i++){
    $c->batchInsert( $batches[$i] );
  }
  $c->findOne();
  $end = micro_time();

  $total = $end - $start;
  $ops = PER_TRIAL/$total;
  echo "total time: $total\n";
  echo "ops/sec: $ops\n";
  echo "------\n";
}

function go($c, $obj)
{
  echo "{insert} $c\n";

  $start = micro_time();
  for($i=0;$i < PER_TRIAL;$i++){
    $obj["x"]=$i;
    $c->insert( $obj );
  }
  $end = micro_time();
  $total = $end - $start;
  $ops = PER_TRIAL/$total;
  echo "total time: $total\n";
  echo "ops/sec: $ops\n";
  echo "------\n";
}

function go_find_one($c, $obj)
{
  echo "{insert/findOne} $c\n";

  $start = micro_time();
  for($i=0;$i < PER_TRIAL;$i++){
    $obj["x"]=$i;
    $c->insert( $obj );
  }
  $x=$c->findOne();

  $end = micro_time();
  $total = $end - $start;
  $ops = PER_TRIAL/$total;
  echo "total time: $total\n";
  echo "ops/sec: $ops\n";
  echo "------\n";
}


function find_one($c)
{
  echo "find_one $c\n";

  $query = array("x" => PER_TRIAL/2);
  $start = micro_time();
  for($i=0;$i<PER_TRIAL;$i++){
    $c->findOne( $query );
  }
  $end = micro_time();
  $total = $end - $start;
  $ops = PER_TRIAL/$total;
  echo "total time: $total\n";
  echo "ops/sec: $ops\n";
  echo "------\n";
}


function find($c)
{
  echo "{find} $c\n";

  $query = array("x" => PER_TRIAL/2);
  $start = micro_time();
  for($i=0;$i<PER_TRIAL;$i++){
    $cursor = $c->find( $query );
    while( $cursor->hasNext() ){
      $cursor->next();
    }
  }
  $end = micro_time();
  $total = $end - $start;
  $ops = PER_TRIAL/$total;
  echo "total time: $total\n";
  echo "ops/sec: $ops\n";
  echo "------\n";
}

function find_range($c)
{
  echo "{find_range} $c\n";

  $query = array("x" => array('$gt' => PER_TRIAL/2,
                              '$lt' => PER_TRIAL/2+BATCH_SIZE));

  $start = micro_time();
  for($i=0;$i<PER_TRIAL;$i++){
    $cursor = $c->find( $query );
    while( $cursor->hasNext() ){
      $cursor->next();
    }
  }
  $end = micro_time();
  $total = $end - $start;
  $ops = PER_TRIAL/$total;
  echo "total time: $total\n";
  echo "ops/sec: $ops\n";
  echo "------\n";
}


$small  = array("x" => 0);
$medium = array("x" => 0, 
                "integer" => 5,
                "number" => 5.05,
                "boolean" => false,
                "array" => array( "test", "benchmark"));
$large  = array("x" => 0, 
                "base_url" => "http://www.example.com/test-me",
                "total_word_count" => 6743,
                "access_time" => new MongoDate(),
                "meta_tags" => array("description" => "i am a long description string",
                                     "author" => "Holly Man",
                                     "dynamically_created_meta_tag" => "who know\n what"
                                     ),
                "page_structure" => array("counted_tags" => 3450,
                                          "no_of_js_attached" => 10,
                                          "no_of_images" => 6
                                          ),
                "harvested_words" => array("10gen","web","open","source","application","paas",
                                        "platform-as-a-service","technology","helps",
                                        "developers","focus","building","mongodb","mongo",
                                        "10gen","web","open","source","application","paas",
                                        "platform-as-a-service","technology","helps",
                                        "developers","focus","building","mongodb","mongo",
                                        "10gen","web","open","source","application","paas",
                                        "platform-as-a-service","technology","helps",
                                        "developers","focus","building","mongodb","mongo",
                                        "10gen","web","open","source","application","paas",
                                        "platform-as-a-service","technology","helps",
                                        "developers","focus","building","mongodb","mongo",
                                        "10gen","web","open","source","application","paas",
                                        "platform-as-a-service","technology","helps",
                                        "developers","focus","building","mongodb","mongo",
                                        "10gen","web","open","source","application","paas",
                                        "platform-as-a-service","technology","helps",
                                        "developers","focus","building","mongodb","mongo",
                                        "10gen","web","open","source","application","paas",
                                        "platform-as-a-service","technology","helps",
                                        "developers","focus","building","mongodb","mongo",
                                        "10gen","web","open","source","application","paas",
                                        "platform-as-a-service","technology","helps",
                                        "developers","focus","building","mongodb","mongo",
                                        "10gen","web","open","source","application","paas",
                                        "platform-as-a-service","technology","helps",
                                        "developers","focus","building","mongodb","mongo",
                                        "10gen","web","open","source","application","paas",
                                        "platform-as-a-service","technology","helps",
                                        "developers","focus","building","mongodb","mongo",
                                        "10gen","web","open","source","application","paas",
                                        "platform-as-a-service","technology","helps",
                                        "developers","focus","building","mongodb","mongo",
                                        "10gen","web","open","source","application","paas",
                                        "platform-as-a-service","technology","helps",
                                        "developers","focus","building","mongodb","mongo",
                                        "10gen","web","open","source","application","paas",
                                        "platform-as-a-service","technology","helps",
                                        "developers","focus","building","mongodb","mongo",
                                        "10gen","web","open","source","application","paas",
                                        "platform-as-a-service","technology","helps",
                                        "developers","focus","building","mongodb","mongo",
                                        "10gen","web","open","source","application","paas",
                                        "platform-as-a-service","technology","helps",
                                        "developers","focus","building","mongodb","mongo",
                                        "10gen","web","open","source","application","paas",
                                        "platform-as-a-service","technology","helps",
                                        "developers","focus","building","mongodb","mongo",
                                        "10gen","web","open","source","application","paas",
                                        "platform-as-a-service","technology","helps",
                                        "developers","focus","building","mongodb","mongo",
                                        "10gen","web","open","source","application","paas",
                                        "platform-as-a-service","technology","helps",
                                        "developers","focus","building","mongodb","mongo",
                                        "10gen","web","open","source","application","paas",
                                        "platform-as-a-service","technology","helps",
                                        "developers","focus","building","mongodb","mongo",
                                        "10gen","web","open","source","application","paas",
                                        "platform-as-a-service","technology","helps",
                                        "developers","focus","building","mongodb","mongo"
                                        )
             );

batch($db->selectCollection("small_none"), $small);
batch($db->selectCollection("medium_none"), $medium);
batch($db->selectCollection("large_none"), $large);

none($db->selectCollection("small_none"), $small);
none($db->selectCollection("medium_none"), $medium);
none($db->selectCollection("large_none"), $large);


index($db->selectCollection("small_index"), $small);
index($db->selectCollection("medium_index"), $medium);
index($db->selectCollection("large_index"), $large);


find_one($db->selectCollection("small_none"));
find_one($db->selectCollection("medium_none"));
find_one($db->selectCollection("large_none"));

find_one($db->selectCollection("small_index"));
find_one($db->selectCollection("medium_index"));
find_one($db->selectCollection("large_index"));

find($db->selectCollection("small_none"));
find($db->selectCollection("medium_none"));
find($db->selectCollection("large_none"));

find($db->selectCollection("small_index"));
find($db->selectCollection("medium_index"));
find($db->selectCollection("large_index"));

find_range($db->selectCollection("small_index"));
find_range($db->selectCollection("medium_index"));
find_range($db->selectCollection("large_index"));

?>