forked from doctrine/mongodb-odm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHydrationPerformanceTest.php
49 lines (38 loc) · 1.21 KB
/
HydrationPerformanceTest.php
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
<?php
namespace Doctrine\Tests\ODM\MongoDB\Performance;
use Documents\CmsUser;
/**
* @group performance
*/
class HydrationPerformanceTest extends \Doctrine\ODM\MongoDB\Tests\BaseTest
{
/**
* [jwage: 10000 objects in ~6 seconds]
*/
public function testHydrationPerformance()
{
$s = microtime(true);
$batchSize = 20;
for ($i = 1; $i <= 10000; ++$i) {
$user = new CmsUser;
$user->status = 'user';
$user->username = 'user' . $i;
$user->name = 'Mr.Smith-' . $i;
$this->dm->persist($user);
if (($i % $batchSize) == 0) {
$this->dm->flush();
$this->dm->clear();
}
}
gc_collect_cycles();
echo "Memory usage before: " . (memory_get_usage() / 1024) . " KB" . PHP_EOL;
$users = $this->dm->getRepository('Documents\CmsUser')->findAll();
foreach ($users as $user) {
}
$this->dm->clear();
gc_collect_cycles();
echo "Memory usage after: " . (memory_get_usage() / 1024) . " KB" . PHP_EOL;
$e = microtime(true);
echo 'Hydrated 10000 objects in ' . ($e - $s) . ' seconds' . PHP_EOL;
}
}