Skip to content

Instantly share code, notes, and snippets.

@jmikola
Created December 5, 2016 14:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jmikola/a6efe8d512615f36b7c6df87951fd4a2 to your computer and use it in GitHub Desktop.
Save jmikola/a6efe8d512615f36b7c6df87951fd4a2 to your computer and use it in GitHub Desktop.
Benchmark findAndModify with manual typeMap conversion
<?php
require 'vendor/autoload.php';
function createNestedDocuments($n, $depth)
{
$document = new stdClass;
if ($depth < 1) {
return $document;
}
foreach (range(1, $n) as $i) {
$document->{'doc' . $i} = createNestedDocuments($n, $depth - 1);
}
return $document;
}
function pass(MongoDB\Collection $collection)
{
$collection->insertOne([
'_id' => 1,
'a' => 'foo',
'b' => str_repeat('b', 1024 * 1024),
'c' => createNestedDocuments(5, 5),
'd' => range(1, 1024),
]);
$document = $collection->findOneAndDelete([]);
echo $document ? '.' : 'x';
}
$collection = (new MongoDB\Client)->test->foo;
$collection->drop();
for ($i = 0; $i < 1000; $i++) {
pass($collection);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment