1
0
mirror of synced 2024-12-14 15:16:04 +03:00
doctrine2/tests/Doctrine/Tests/ORM/Performance/InsertPerformanceTest.php

56 lines
1.3 KiB
PHP
Raw Normal View History

2009-05-19 20:11:08 +04:00
<?php
namespace Doctrine\Tests\ORM\Performance;
require_once __DIR__ . '/../../TestInit.php';
use Doctrine\Tests\Models\CMS\CmsUser;
/**
* Description of InsertPerformanceTest
*
* @author robo
*/
class InsertPerformanceTest extends \Doctrine\Tests\OrmPerformanceTestCase
{
protected function setUp() {
$this->useModelSet('cms');
parent::setUp();
}
/**
* [romanb: 10000 objects in ~8 seconds]
*/
public function testInsertPerformance()
{
$s = microtime(true);
$conn = $this->_em->getConnection();
$this->setMaxRunningTime(10);
//$mem = memory_get_usage();
//echo "Memory usage before: " . ($mem / 1024) . " KB" . PHP_EOL;
2009-05-19 20:24:17 +04:00
$batchSize = 20;
2009-05-19 20:11:08 +04:00
for ($i=0; $i<10000; ++$i) {
$user = new CmsUser;
$user->status = 'user';
$user->username = 'user' . $i;
$user->name = 'Mr.Smith-' . $i;
2009-07-19 20:54:53 +04:00
$this->_em->persist($user);
2009-05-19 20:24:17 +04:00
if (($i % $batchSize) == 0) {
2009-05-19 20:11:08 +04:00
$this->_em->flush();
$this->_em->clear();
}
}
//$memAfter = memory_get_usage();
//echo "Memory usage after: " . ($memAfter / 1024) . " KB" . PHP_EOL;
$e = microtime(true);
2009-05-19 20:24:17 +04:00
echo ' Inserted 10000 objects in ' . ($e - $s) . ' seconds' . PHP_EOL;
2009-05-19 20:11:08 +04:00
}
}