Skip to content

Commit 8fcee0d

Browse files
committed
added scripts for testing performance
1 parent 5843872 commit 8fcee0d

File tree

5 files changed

+335
-0
lines changed

5 files changed

+335
-0
lines changed

Diff for: test-performance/README.rst

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
===============================
2+
How to execute performance test
3+
===============================
4+
5+
Get Doctrine 1
6+
==============
7+
8+
execute following::
9+
10+
$ svn co http://svn.doctrine-project.org/tags/1.2.2 /path/to/Doctrine-1.2.2
11+
12+
Run test script
13+
===============
14+
15+
execute following (path to your Doctrine 1.2 must end with "/")::
16+
17+
$ cd /path/to/dql-tokenizer-root-dir
18+
$ DQL_TOKENIZER_TEST_DOCTRINE_ROOT_DIR="/path/to/Doctrine-1.2.2/" sh test-performance/execute-dql.sh

Diff for: test-performance/execute-dql.php

+158
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
1+
<?php
2+
3+
4+
5+
if (!isset($_SERVER['DQL_TOKENIZER_TEST_DOCTRINE_ROOT_DIR']))
6+
{
7+
echo 'Set $DQL_TOKENIZER_TEST_DOCTRINE_ROOT_DIR before executing this script'.PHP_EOL;
8+
9+
exit;
10+
}
11+
12+
define('DOCTRINE_DIR', $_SERVER['DQL_TOKENIZER_TEST_DOCTRINE_ROOT_DIR']);
13+
define('LOOP_COUNT', (isset($argv[1])) ? $argv[1] : 100);
14+
15+
require_once DOCTRINE_DIR.'/lib/Doctrine.php';
16+
17+
spl_autoload_register(array('Doctrine', 'autoload'));
18+
19+
$a = new Doctrine_Adapter_Mock('Mysql');
20+
$c = Doctrine_Manager::getInstance()->openConnection($a, 'Mysql');
21+
$c->setAttribute(Doctrine_Core::ATTR_TABLE_CLASS, 'Doctrine_Table');
22+
$c->setAttribute(Doctrine_Core::ATTR_DEFAULT_COLUMN_OPTIONS, array());
23+
$c->setAttribute(Doctrine_Core::ATTR_LISTENER, new Doctrine_EventListener());
24+
25+
class ExampleRecord extends Doctrine_Record
26+
{
27+
public function setTableDefinition()
28+
{
29+
$this->setTableName('example_record');
30+
$this->hasColumn('id', 'integer', 4, array('primary' => true));
31+
}
32+
33+
public function setUp()
34+
{
35+
parent::setUp();
36+
37+
$this->hasOne('ExampleRecord', array(
38+
'local' => 'id',
39+
'foreign' => 'id',
40+
'onDelete' => 'cascade',
41+
));
42+
}
43+
}
44+
45+
require_once dirname(__FILE__).'/../example/myQueryTokenizer.class.php';
46+
class myQuery extends Doctrine_Query
47+
{
48+
public function __construct(Doctrine_Connection $connection = null, Doctrine_Hydrator_Abstract $hydrator = null)
49+
{
50+
parent::__construct($connection, $hydrator);
51+
52+
$this->_tokenizer = new myDqlTokenizer();
53+
}
54+
}
55+
56+
function execute_string_query($c, $str)
57+
{
58+
$query = new Doctrine_Query($c);
59+
$my_query = new myQuery($c);
60+
61+
echo $str."\t";
62+
63+
$begin = microtime(true);
64+
for ($i = 0; $i < LOOP_COUNT; $i++)
65+
{
66+
$query->query($str);
67+
}
68+
echo (microtime(true) - $begin)."\t";
69+
70+
$begin = microtime(true);
71+
for ($i = 0; $i < LOOP_COUNT; $i++)
72+
{
73+
$my_query->query($str);
74+
}
75+
echo (microtime(true) - $begin)."\t";
76+
77+
echo PHP_EOL;
78+
}
79+
80+
function execute_constructed_dql($c, $parts)
81+
{
82+
$query = new Doctrine_Query($c);
83+
foreach ($parts as $p)
84+
{
85+
$query->$p[0]($p[1]);
86+
}
87+
88+
$my_query = new myQuery($c);
89+
foreach ($parts as $p)
90+
{
91+
$my_query->$p[0]($p[1]);
92+
}
93+
94+
echo '[constructed]'.$query->getDql()."\t";
95+
96+
$begin = microtime(true);
97+
for ($i = 0; $i < LOOP_COUNT; $i++)
98+
{
99+
$query->execute();
100+
}
101+
echo (microtime(true) - $begin)."\t";
102+
103+
$begin = microtime(true);
104+
for ($i = 0; $i < LOOP_COUNT; $i++)
105+
{
106+
$my_query->execute();
107+
}
108+
echo (microtime(true) - $begin)."\t";
109+
110+
echo PHP_EOL;
111+
}
112+
113+
// ---------------------------------------------------------
114+
115+
echo "query\tnormal-tokenizer\tphp-dql-tokenizer".PHP_EOL;
116+
117+
execute_string_query($c, 'SELECT * FROM ExampleRecord');
118+
execute_string_query($c, 'SELECT id, id, id, id, id, id, id FROM ExampleRecord');
119+
execute_string_query($c, 'SELECT a.id, a.id, a.id, a.id, a.id, a.id, a.id FROM ExampleRecord AS a');
120+
execute_string_query($c, 'SELECT id, id, id, id, id, id, id FROM ExampleRecord WHERE id = ?');
121+
execute_string_query($c, 'SELECT id, id, id, id, id, id, id FROM ExampleRecord WHERE id = ? AND id IN (?, ?, ?, ?)');
122+
execute_string_query($c, 'SELECT id, id, id, id, id, id, id FROM ExampleRecord WHERE id = ? AND id IN (?, ?, ?, ?) AND id = (SELECT s.id FROM ExampleRecord.ExampleRecord AS s WHERE s.id = ?)');
123+
124+
execute_string_query($c, 'DELETE FROM ExampleRecord');
125+
execute_string_query($c, 'DELETE FROM ExampleRecord WHERE id = ? AND id > 10 AND id < 10');
126+
127+
// too slow (both of Doctrine_Query and myQuery)
128+
/*
129+
execute_string_query($c, 'UPDATE ExampleRecord SET id = ?, id = ? WHERE id = ?');
130+
execute_string_query($c, 'UPDATE ExampleRecord SET id = ?, id = ? WHERE id IN (?)');
131+
*/
132+
133+
execute_constructed_dql($c, array(
134+
array('from', 'ExampleRecord'),
135+
));
136+
137+
execute_constructed_dql($c, array(
138+
array('from', 'ExampleRecord'),
139+
array('select', 'id, id'),
140+
));
141+
142+
execute_constructed_dql($c, array(
143+
array('from', 'ExampleRecord'),
144+
array('select', 'id, id, id, id, id'),
145+
array('where', 'id = ?'),
146+
array('andWhere', 'id = ?'),
147+
array('andWhere', 'id IN ?'),
148+
));
149+
150+
execute_constructed_dql($c, array(
151+
array('from', 'ExampleRecord'),
152+
array('delete', ''),
153+
array('where', 'id = ?'),
154+
array('andWhere', 'id = ?'),
155+
array('andWhere', 'id IN ?'),
156+
));
157+
158+
Doctrine_Manager::resetInstance(); unset($a, $c);

Diff for: test-performance/execute-dql.sh

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
cd test-performance
2+
3+
i=1
4+
while [ $i -le 16384 ]
5+
do
6+
echo $i":"
7+
php execute-dql.php $i
8+
9+
i=`expr $i "*" 2`
10+
done

Diff for: test-performance/memory.php

+126
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
<?php
2+
3+
$funcName = ($argc == 1) ? 'default' : $argv[1];
4+
var_dump('Current: '.$funcName);
5+
6+
$time = microtime(true);
7+
$m = memory_get_usage();
8+
9+
for ($i = 0; $i < 100; $i++)
10+
{
11+
if ('dql_get_split_regexp_from_array' === $funcName)
12+
{
13+
dql_get_split_regexp_from_array(array('s', 'str', ' ', '\\', '|', '(', '*', 0, true));
14+
}
15+
16+
if ('dql_sql_explode' === $funcName)
17+
{
18+
dql_sql_explode("(age < 20 AND age > 18) AND name LIKE 'John Doe'", ' ', '(', ')');
19+
}
20+
21+
if ('dql_tokenize_query' === $funcName)
22+
{
23+
dql_tokenize_query("SELECT u.* FROM User u WHERE u.name LIKE ?");
24+
}
25+
26+
if ('dql_bracket_trim' === $funcName)
27+
{
28+
dql_bracket_trim("(SELECT u.* FROM User u WHERE u.name LIKE ?)");
29+
}
30+
31+
if ('dql_bracket_explode' === $funcName)
32+
{
33+
dql_bracket_explode("(age < 20 AND age > 18) AND email LIKE '[email protected]'");
34+
}
35+
36+
if ('dql_clause_explode' === $funcName)
37+
{
38+
dql_clause_explode("(age < 20 AND age > 18) AND name LIKE 'John'+' Doe'", array(' ', '+'));
39+
}
40+
41+
if ('dql_quote_explode' === $funcName)
42+
{
43+
dql_quote_explode("email LIKE '[email protected]'", ' LIKE ');
44+
}
45+
46+
if ('dql_quoted_string_explode' === $funcName)
47+
{
48+
dql_quoted_string_explode("'a' AND name = 'John O\'Connor'");
49+
}
50+
51+
if ('dql_clause_explode_count_brackets' === $funcName)
52+
{
53+
dql_clause_explode_count_brackets("'a' AND name = 'John O\'Connor'", '#(\s)#');
54+
}
55+
56+
if ('dql_clause_explode_non_quoted' === $funcName)
57+
{
58+
dql_clause_explode_non_quoted("dctrn_find.id = ?", '#( |\s)#');
59+
}
60+
61+
if ('dql_clause_explode_regexp' === $funcName)
62+
{
63+
dql_clause_explode_regexp("dctrn_find.id IN (?)", '#( |\s)#', '(', ')');
64+
}
65+
66+
if ('dql_merge_bracket_terms' === $funcName)
67+
{
68+
dql_merge_bracket_terms(array(array("'a(b'", '+', 0), array('(2', '+', 1), array('3)', '-', -1), array('5', '' , '0')));
69+
}
70+
71+
if ('tokenizeA' === $funcName)
72+
{
73+
dql_tokenize_query('SELECT * FROM ExampleRecord');
74+
}
75+
76+
if ('tokenizeB' === $funcName)
77+
{
78+
dql_tokenize_query('SELECT id, id, id, id, id, id, id FROM ExampleRecord');
79+
}
80+
81+
if ('tokenizeC' === $funcName)
82+
{
83+
dql_tokenize_query('SELECT a.id, a.id, a.id, a.id, a.id, a.id, a.id FROM ExampleRecord AS a');
84+
}
85+
86+
if ('tokenizeD' === $funcName)
87+
{
88+
dql_tokenize_query('SELECT id, id, id, id, id, id, id FROM ExampleRecord WHERE id = ?');
89+
}
90+
91+
if ('tokenizeE' === $funcName)
92+
{
93+
dql_tokenize_query('SELECT id, id, id, id, id, id, id FROM ExampleRecord WHERE id = ? AND id IN (?, ?, ?, ?)');
94+
}
95+
96+
if ('tokenizeF' === $funcName)
97+
{
98+
dql_tokenize_query('SELECT id, id, id, id, id, id, id FROM ExampleRecord WHERE id = ? AND id IN (?, ?, ?, ?) AND id = (SELECT s.id FROM ExampleRecord.ExampleRecord AS s WHERE s.id = ?)');
99+
}
100+
101+
if ('tokenizeG' === $funcName)
102+
{
103+
dql_tokenize_query('DELETE FROM ExampleRecord');
104+
}
105+
106+
if ('tokenizeH' === $funcName)
107+
{
108+
dql_tokenize_query('DELETE FROM ExampleRecord WHERE id = ? AND id > 10 AND id < 10');
109+
}
110+
111+
if ('tokenizeI' === $funcName)
112+
{
113+
dql_tokenize_query('UPDATE ExampleRecord SET id = ?, id = ? WHERE id = ?');
114+
}
115+
116+
if ('tokenizeJ' === $funcName)
117+
{
118+
dql_tokenize_query('UPDATE ExampleRecord SET id = ?, id = ? WHERE id IN (?)');
119+
}
120+
}
121+
122+
var_dump(
123+
'Memory: '.(memory_get_usage() - $m),
124+
'Time : '.(microtime(true) - $time),
125+
round(memory_get_usage() / 1024 / 1024, 2)
126+
);

Diff for: test-performance/memory.sh

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
cd test-performance
2+
php memory.php dql_get_split_regexp_from_array
3+
php memory.php dql_sql_explode
4+
php memory.php dql_tokenize_query
5+
php memory.php dql_bracket_trim
6+
php memory.php dql_bracket_explode
7+
php memory.php dql_clause_explode
8+
php memory.php dql_quote_explode
9+
php memory.php dql_quoted_string_explode
10+
php memory.php dql_clause_explode_count_brackets
11+
php memory.php dql_clause_explode_non_quoted
12+
php memory.php dql_clause_explode_regexp
13+
php memory.php dql_merge_bracket_terms
14+
php memory.php tokenizeA
15+
php memory.php tokenizeB
16+
php memory.php tokenizeC
17+
php memory.php tokenizeD
18+
php memory.php tokenizeE
19+
php memory.php tokenizeF
20+
php memory.php tokenizeG
21+
php memory.php tokenizeH
22+
php memory.php tokenizeI
23+
php memory.php tokenizeJ

0 commit comments

Comments
 (0)