-
-
Save jaymecd/9730797 to your computer and use it in GitHub Desktop.
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
#!/usr/bin/env php | |
<?php | |
use Doctrine\ODM\MongoDB\DocumentManager; | |
use Doctrine\MongoDB\Connection; | |
require_once __DIR__.'/vendor/autoload.php'; | |
require_once __DIR__.'/Document.php'; | |
$config = require_once __DIR__.'/config.php'; | |
$dm = DocumentManager::create(new Connection(), $config); | |
$collection = $dm->getDocumentCollection('Document')->getMongoCollection(); | |
$sizes = array_slice($argv, 1); | |
foreach ($sizes as $i) { | |
$preMem = memory_get_usage(true); | |
$preTime = microtime(true); | |
foreach (range(1, $i) as $j) { | |
$document = new Document(); | |
$document->name = sprintf('doc-%d-%d', $i, $j); | |
$collection->insert(array('name' => $document->name)); | |
} | |
$postMem = memory_get_usage(true); | |
$postTime = microtime(true); | |
$collection->drop(); | |
printf("Inserting %d documents took %f seconds and used %d bytes\n", $i, $postTime - $preTime, $postMem - $preMem); | |
} | |
printf("%d bytes still allocated after benchmarking\n", memory_get_usage(true)); |
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
#!/usr/bin/env php | |
<?php | |
use Doctrine\ODM\MongoDB\DocumentManager; | |
use Doctrine\MongoDB\Connection; | |
require_once __DIR__.'/vendor/autoload.php'; | |
require_once __DIR__.'/Document.php'; | |
$config = require_once __DIR__.'/config.php'; | |
$dm = DocumentManager::create(new Connection(), $config); | |
$collection = $dm->getDocumentCollection('Document'); | |
$sizes = array_slice($argv, 1); | |
foreach ($sizes as $i) { | |
$preMem = memory_get_usage(true); | |
$preTime = microtime(true); | |
foreach (range(1, $i) as $j) { | |
$document = new Document(); | |
$document->name = sprintf('doc-%d-%d', $i, $j); | |
// See: https://github.com/doctrine/mongodb/issues/55 | |
$a = array('name' => $document->name); | |
$collection->insert($a); | |
} | |
$postMem = memory_get_usage(true); | |
$postTime = microtime(true); | |
$collection->drop(); | |
printf("Inserting %d documents took %f seconds and used %d bytes\n", $i, $postTime - $preTime, $postMem - $preMem); | |
} | |
printf("%d bytes still allocated after benchmarking\n", memory_get_usage(true)); |
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
#!/usr/bin/env php | |
<?php | |
use Doctrine\ODM\MongoDB\DocumentManager; | |
use Doctrine\MongoDB\Connection; | |
require_once __DIR__.'/vendor/autoload.php'; | |
require_once __DIR__.'/Document.php'; | |
$config = require_once __DIR__.'/config.php'; | |
$dm = DocumentManager::create(new Connection(), $config); | |
$sizes = array_slice($argv, 1); | |
foreach ($sizes as $i) { | |
$preMem = memory_get_usage(true); | |
$preTime = microtime(true); | |
foreach (range(1, $i) as $j) { | |
$document = new Document(); | |
$document->name = sprintf('doc-%d-%d', $i, $j); | |
$dm->persist($document); | |
} | |
$dm->flush(); | |
$postMem = memory_get_usage(true); | |
$postTime = microtime(true); | |
$dm->clear(); | |
$dm->getDocumentCollection('Document')->drop(); | |
printf("Flushing %d documents took %f seconds and used %d bytes\n", $i, $postTime - $preTime, $postMem - $preMem); | |
} | |
printf("%d bytes still allocated after benchmarking\n", memory_get_usage(true)); |
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
#!/usr/bin/env php | |
<?php | |
use Doctrine\ODM\MongoDB\DocumentManager; | |
use Doctrine\MongoDB\Connection; | |
require_once __DIR__.'/vendor/autoload.php'; | |
require_once __DIR__.'/Document.php'; | |
$config = require_once __DIR__.'/config.php'; | |
$dm = DocumentManager::create(new Connection(), $config); | |
$sizes = array_slice($argv, 1); | |
foreach ($sizes as $i) { | |
$preMem = memory_get_usage(true); | |
$preTime = microtime(true); | |
foreach (range(1, $i) as $j) { | |
$document = new Document(); | |
$document->name = sprintf('doc-%d-%d', $i, $j); | |
$dm->createQueryBuilder('Document') | |
->insert() | |
->field('name')->set($document->name) | |
->getQuery() | |
->execute(); | |
} | |
$postMem = memory_get_usage(true); | |
$postTime = microtime(true); | |
$dm->getDocumentCollection('Document')->drop(); | |
printf("Inserting %d documents took %f seconds and used %d bytes\n", $i, $postTime - $preTime, $postMem - $preMem); | |
} | |
printf("%d bytes still allocated after benchmarking\n", memory_get_usage(true)); |
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
{ | |
"require": { | |
"doctrine/mongodb-odm": "dev-master" | |
} | |
} |
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 | |
use Doctrine\ODM\MongoDB\Mapping\Driver\AnnotationDriver; | |
use Doctrine\ODM\MongoDB\Configuration; | |
AnnotationDriver::registerAnnotationClasses(); | |
$cacheDir = __DIR__; | |
$config = new Configuration(); | |
$config->setProxyDir($cacheDir . '/Proxies'); | |
$config->setProxyNamespace('Proxies'); | |
$config->setHydratorDir($cacheDir . '/Hydrators'); | |
$config->setHydratorNamespace('Hydrators'); | |
$config->setMetadataDriverImpl(AnnotationDriver::create(__DIR__)); | |
$config->setDefaultDB('benchmark'); | |
return $config; |
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 | |
use Doctrine\ODM\MongoDB\Mapping\Annotations as Mongo; | |
/** @Mongo\Document(collection="documents") */ | |
class Document | |
{ | |
/** @Mongo\Id */ | |
public $id; | |
/** @Mongo\String */ | |
public $name; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment