Created
December 5, 2016 14:58
-
-
Save jmikola/a6efe8d512615f36b7c6df87951fd4a2 to your computer and use it in GitHub Desktop.
Benchmark findAndModify with manual typeMap conversion
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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