Zyx: specjalnie, żeby nie było pytań o metodologię i na użytek innych dałem link do skryptu, którym testowałem.
Jest to czas w mikrosekundach jaki dany ORM potrzebował na wykonanie zapytania.
Tu masz główną klasę abstract:
public function initTables()
{
try {
$this->con->exec('DROP TABLE [book]');
$this->con->exec('DROP TABLE [author]');
} catch (PDOException $e) {
// do nothing - the tables probably don't exist yet
}
$this->con->exec('CREATE TABLE [book]
(
[id] INTEGER NOT NULL PRIMARY KEY,
[title] VARCHAR(255) NOT NULL,
[isbn] VARCHAR(24) NOT NULL,
[price] FLOAT,
[author_id] INTEGER
)');
$this->con->exec('CREATE TABLE [author]
(
[id] INTEGER NOT NULL PRIMARY KEY,
[first_name] VARCHAR(128) NOT NULL,
[last_name] VARCHAR(128) NOT NULL,
[email] VARCHAR(128)
)');
}
public function run()
{
$t1 = $this->runTest('runAuthorInsertion', 1700);
$t1 += $this->runTest('runBookInsertion', 1700);
$t2 = $this->runTest('runPKSearch', 1900);
$t3 = $this->runTest('runComplexQuery', 190);
$t4 = $this->runTest('runHydrate', 750);
$t5 = $this->runTest('runJoinSearch', 700);
echo sprintf("%30s | %6d | %6d | %6d | %6d | %6d |\n", get_class
($this), $t1, $t2, $t3, $t4, $t5); }
a tu klase od Doctrine 1.2, która dziedziczy z tej abstrakcyjnej:function runAuthorInsertion($i)
{
$author = new Author();
$author->first_name = 'John' . $i;
$author->last_name = 'Doe' . $i;
$author->save($this->con);
$this->authors[]= $author->id;
}
function runBookInsertion($i)
{
$book = new Book();
$book->title = 'Hello' . $i;
$book->author_id = $this->authors[array_rand($this->authors)]; $book->isbn = '1234';
$book->price = $i;
$book->save($this->con);
$this->books[]= $book->id;
}
function runPKSearch($i)
{
$author = Doctrine_Core
::getTable('Author')->find($this->authors[array_rand($this->authors)]); }
function runComplexQuery($i)
{
$authors = Doctrine_Query::create()
->from('Author a')
->where('a.id > ?', $this->authors[array_rand($this->authors)]) ->orWhere('(a.first_name || a.last_name) = ?', 'John Doe')
->limit(5)
->count();
}
function runHydrate($i)
{
$books = Doctrine_Query::create()
->from('Book b')
->where('b.price > ?', $i)
->limit(5)
->execute();
foreach ($books as $book) {
// removing the record from the instance pool, otherwise we are not testing hydration time!
$book->free(true);
}
}
function runJoinSearch($i)
{
$book = Doctrine_Query::create()
->from('Book b')
->leftJoin('b.Author a')
->where('b.title = ?', 'Hello' . $i)
->limit(1)
->fetchOne();
}