Author: uwendel
Date: 2007-03-20 16:09:00 +0100 (Tue, 20 Mar 2007)
New Revision: 211
Added:
trunk/ext/mysqli/tests/bench/micro_benches/andrey_stmt1.php
trunk/ext/mysqli/tests/bench/micro_benches/andrey_stmt2.php
trunk/ext/mysqli/tests/bench/micro_benches/mysqli_stmt_data_seek_random.php
trunk/ext/mysqli/tests/bench/micro_benches/mysqli_stmt_data_seek_sequential.php
trunk/ext/mysqli/tests/bench/micro_benches/mysqli_stmt_execute.php
trunk/ext/mysqli/tests/bench/micro_benches/mysqli_stmt_execute_insert_varchar.php
trunk/ext/mysqli/tests/bench/micro_benches/mysqli_stmt_execute_select_varchar_buffered.php
trunk/ext/mysqli/tests/bench/micro_benches/mysqli_stmt_execute_select_varchar_unbuffered.php
trunk/ext/mysqli/tests/bench/micro_benches/mysqli_stmt_fetch_many_columns_unbuffered.php
Log:
Ported a few non prepared-statement benchmarks to prepared-statements. My initial
impression is that mysqlnd prepared statement are not that slow as we might fear.
Added: trunk/ext/mysqli/tests/bench/micro_benches/andrey_stmt1.php
===================================================================
--- trunk/ext/mysqli/tests/bench/micro_benches/andrey_stmt1.php 2007-03-20 15:05:27 UTC
(rev 210)
+++ trunk/ext/mysqli/tests/bench/micro_benches/andrey_stmt1.php 2007-03-20 15:09:00 UTC
(rev 211)
@@ -0,0 +1,98 @@
+<?PHP
+/* Config settings should go at the very beginning */
+$rows = array(100, 1000, 10000, 100000);
+
+// Set a description
+$description = 'This is a skeleton for a benchmark that does nothing.';
+
+
+/*
+ This is a hash that stores the runtimes
+ It is dumped in all reports. The hash keys will be used as labels/descriptions.
+ $times['select()'] = 0.01; => shown in reports like 'select() : 0.01s'
+*/
+$times = array();
+/*
+ It's recommended to initialize the times hash with 0 values
+ for all entries. This often makes debugging easier.
+ Make sure you have one 'overall' entry in your list which
+ holds the 'entire runtime' of you test (e.g. create table + insert + select) and not
only
+ a fraction of it (e.g. select).
+*/
+foreach ($rows as $k => $num_rows) {
+ $times[sprintf("%7d: overall", $num_rows)] = 0;
+ $times[sprintf("%7d: query", $num_rows)] = 0;
+ $times[sprintf("%7d: fetch()", $num_rows)] = 0;
+}
+
+/*
+ List of errors that happened during the test run. You should stop
+ the benchmark after the first error
+*/
+$errors = array();
+
+
+do {
+
+ if (!$link = mysqli_connect($host, $user, $passwd, $db, $port, $socket)) {
+ $errors[] = sprintf("Connect failure (converted code: %s)\n", ($flag_original_code) ?
'no' : 'yes');
+ break;
+ }
+
+ if (!mysqli_query($link, "DROP TABLE IF EXISTS test")) {
+ $errors[] = sprintf("DROP TABLE IF EXISTS failure (converted code: %s)\n",
($flag_original_code) ? 'no' : 'yes');
+ break;
+ }
+
+ if (!mysqli_query($link, "CREATE TABLE test(a INT, b CHAR(1), c CHAR(1), d CHAR(1))"))
{
+ $errors[] = sprintf("CREATE TABLE failure (converted code: %s)\n",
($flag_original_code) ? 'no' : 'yes');
+ break;
+ }
+
+ foreach ($rows as $k => $num_rows) {
+
+ if (!mysqli_query($link, "TRUNCATE TABLE test")) {
+ $errors[] = sprintf("TRUNCATE failure (converted code: %s)\n",
($flag_original_code) ? 'no' : 'yes');
+ break 2;
+ }
+ for ($i = 0; $i < $num_rows; $i++) {
+ if (!mysqli_query($link, sprintf("INSERT INTO test(a, b, c, d) VALUES (%d, 'a',
'b', 'c')", $i))) {
+ $errors[] = sprintf("TRUNCATE failure (converted code: %s)\n",
($flag_original_code) ? 'no' : 'yes');
+ break 3;
+ }
+ }
+
+ $times[sprintf("%7d: overall", $num_rows)] = $start = microtime(true);
+
+ if (!$stmt = mysqli_stmt_init($link)) {
+ $errors[] = sprintf("stmt_init() failure (converted code: %s)\n",
($flag_original_code) ? 'no' : 'yes');
+ break 2;
+ }
+ if (!mysqli_stmt_prepare($stmt, 'SELECT * FROM test')) {
+ $errors[] = sprintf("stmt_prepare() failure (converted code: %s)\n",
($flag_original_code) ? 'no' : 'yes');
+ break 2;
+ }
+ if (!mysqli_stmt_execute($stmt)) {
+ $errors[] = sprintf("stmt_execute() failure (converted code: %s)\n",
($flag_original_code) ? 'no' : 'yes');
+ break 2;
+ }
+
+ $row = array(0 => null, 1 => null, 2 => null, 3 => null);
+ if (!mysqli_stmt_bind_result($stmt, $row[0], $row[1], $row[2], $row[3])) {
+ $errors[] = sprintf("stmt_execute() failure (converted code: %s)\n",
($flag_original_code) ? 'no' : 'yes');
+ break 2;
+ }
+ $times[sprintf("%7d: query", $num_rows)] = (microtime(true) - $start);
+
+ $start = microtime(true);
+ while (mysqli_stmt_fetch($stmt))
+ ;
+ $times[sprintf("%7d: stmt_fetch()", $num_rows)] = (microtime(true) - $start);
+
+ $times[sprintf("%7d: overall", $num_rows)] = (microtime(true) - $times[sprintf("%7d:
overall", $num_rows)]);
+ }
+
+ mysqli_close($link);
+
+} while (false);
+?>
\ No newline at end of file
Added: trunk/ext/mysqli/tests/bench/micro_benches/andrey_stmt2.php
===================================================================
--- trunk/ext/mysqli/tests/bench/micro_benches/andrey_stmt2.php 2007-03-20 15:05:27 UTC
(rev 210)
+++ trunk/ext/mysqli/tests/bench/micro_benches/andrey_stmt2.php 2007-03-20 15:09:00 UTC
(rev 211)
@@ -0,0 +1,100 @@
+<?PHP
+/* Config settings should go at the very beginning */
+$rows = array(100, 1000, 10000, 100000);
+
+// Set a description
+$description = 'This is a skeleton for a benchmark that does nothing.';
+
+
+/*
+ This is a hash that stores the runtimes
+ It is dumped in all reports. The hash keys will be used as labels/descriptions.
+ $times['select()'] = 0.01; => shown in reports like 'select() : 0.01s'
+*/
+$times = array();
+/*
+ It's recommended to initialize the times hash with 0 values
+ for all entries. This often makes debugging easier.
+ Make sure you have one 'overall' entry in your list which
+ holds the 'entire runtime' of you test (e.g. create table + insert + select) and not
only
+ a fraction of it (e.g. select).
+*/
+foreach ($rows as $k => $num_rows) {
+ $times[sprintf("%7d: overall", $num_rows)] = 0;
+ $times[sprintf("%7d: query", $num_rows)] = 0;
+ $times[sprintf("%7d: fetch()", $num_rows)] = 0;
+}
+
+/*
+ List of errors that happened during the test run. You should stop
+ the benchmark after the first error
+*/
+$errors = array();
+
+
+do {
+
+ if (!$link = mysqli_connect($host, $user, $passwd, $db, $port, $socket)) {
+ $errors[] = sprintf("Connect failure (converted code: %s)\n", ($flag_original_code) ?
'no' : 'yes');
+ break;
+ }
+
+ if (!mysqli_query($link, "DROP TABLE IF EXISTS test")) {
+ $errors[] = sprintf("DROP TABLE IF EXISTS failure (converted code: %s)\n",
($flag_original_code) ? 'no' : 'yes');
+ break;
+ }
+
+ if (!mysqli_query($link, "CREATE TABLE test(a INT, b CHAR(255), c CHAR(255), d
CHAR(255))")) {
+ $errors[] = sprintf("CREATE TABLE failure (converted code: %s)\n",
($flag_original_code) ? 'no' : 'yes');
+ break;
+ }
+
+ foreach ($rows as $k => $num_rows) {
+
+ if (!mysqli_query($link, "TRUNCATE TABLE test")) {
+ $errors[] = sprintf("TRUNCATE failure (converted code: %s)\n",
($flag_original_code) ? 'no' : 'yes');
+ break 2;
+ }
+ $label = str_repeat('a', 255);
+ for ($i = 0; $i < $num_rows; $i++) {
+ if (!mysqli_query($link, sprintf("INSERT INTO test(a, b, c, d) VALUES (%d, '%s',
'%s', '%s')",
+ $i, $label, $label, $label))) {
+ $errors[] = sprintf("TRUNCATE failure (converted code: %s)\n",
($flag_original_code) ? 'no' : 'yes');
+ break 3;
+ }
+ }
+
+ $times[sprintf("%7d: overall", $num_rows)] = $start = microtime(true);
+
+ if (!$stmt = mysqli_stmt_init($link)) {
+ $errors[] = sprintf("stmt_init() failure (converted code: %s)\n",
($flag_original_code) ? 'no' : 'yes');
+ break 2;
+ }
+ if (!mysqli_stmt_prepare($stmt, 'SELECT * FROM test')) {
+ $errors[] = sprintf("stmt_prepare() failure (converted code: %s)\n",
($flag_original_code) ? 'no' : 'yes');
+ break 2;
+ }
+ if (!mysqli_stmt_execute($stmt)) {
+ $errors[] = sprintf("stmt_execute() failure (converted code: %s)\n",
($flag_original_code) ? 'no' : 'yes');
+ break 2;
+ }
+
+ $row = array(0 => null, 1 => null, 2 => null, 3 => null);
+ if (!mysqli_stmt_bind_result($stmt, $row[0], $row[1], $row[2], $row[3])) {
+ $errors[] = sprintf("stmt_execute() failure (converted code: %s)\n",
($flag_original_code) ? 'no' : 'yes');
+ break 2;
+ }
+ $times[sprintf("%7d: query", $num_rows)] = (microtime(true) - $start);
+
+ $start = microtime(true);
+ while (mysqli_stmt_fetch($stmt))
+ ;
+ $times[sprintf("%7d: stmt_fetch()", $num_rows)] = (microtime(true) - $start);
+
+ $times[sprintf("%7d: overall", $num_rows)] = (microtime(true) - $times[sprintf("%7d:
overall", $num_rows)]);
+ }
+
+ mysqli_close($link);
+
+} while (false);
+?>
\ No newline at end of file
Added: trunk/ext/mysqli/tests/bench/micro_benches/mysqli_stmt_data_seek_random.php
===================================================================
--- trunk/ext/mysqli/tests/bench/micro_benches/mysqli_stmt_data_seek_random.php 2007-03-20
15:05:27 UTC (rev 210)
+++ trunk/ext/mysqli/tests/bench/micro_benches/mysqli_stmt_data_seek_random.php 2007-03-20
15:09:00 UTC (rev 211)
@@ -0,0 +1,148 @@
+<?PHP
+$runs = array(10, 100);
+$rows = array(100, 1000);
+$types = array(
+ 16 => 'varchar(16)',
+ 32 => 'varchar(32)',
+ 64 => 'varchar(64)',
+ 128 => 'varchar(128)',
+ 256 => 'varchar(256)',
+ 512 => 'varchar(512)',
+ 1024 => 'varchar(1024)',
+ 2048 => 'varchar(2048)',
+ 4192 => 'varchar(4192)',
+ 8384 => 'varchar(8384)',
+ 16768 => 'varchar(16768)',
+ 33536 => 'varchar(33536)',
+ 65500 => 'varchar(65500)'
+
+ );
+foreach ($runs as $k => $num_runs) {
+ foreach ($rows as $k => $num_rows) {
+ foreach ($types as $len => $type) {
+ $times[$num_rows . ' rows: ' . $num_runs . 'x ' . $type . ' overall'] = 0;
+ $times[$num_rows . ' rows: ' . $num_runs . 'x ' . $type . ' data_seek()'] = 0;
+ }
+ }
+}
+$description = 'Connect, create n-rows with varchar(m), SELECT all, o-times [$runs]
mysqli_stmt_data_seek(mt_rand()), close. n, m and o vary.';
+$errors = array();
+
+do {
+
+ if (!$link = mysqli_connect($host, $user, $passwd, $db, $port, $socket)) {
+ $errors[] = sprintf("Connect failure (converted code: %s)\n", ($flag_original_code) ?
'no' : 'yes');
+ break;
+ }
+
+ foreach ($types as $len => $type) {
+
+ if (!mysqli_query($link, "DROP TABLE IF EXISTS test")) {
+ $errors[] = sprintf("DROP TABLE failed (converted code: %s): [%d] %s\n",
+ ($flag_original_code) ? 'no' : 'yes',
+ mysqli_errno($link), mysqli_error($link));
+ break 2;
+ }
+
+ $sql = sprintf("CREATE TABLE test(id INT, label %s)", $type);
+ if (!mysqli_query($link, $sql)) {
+ $errors[] = sprintf("CREATE TABLE (%s) failed (converted code: %s): [%d] %s\n",
+ $sql,
+ ($flag_original_code) ? 'no' : 'yes',
+ mysqli_errno($link), mysqli_error($link));
+ break 2;
+ }
+
+ foreach ($rows as $k => $num_rows) {
+ foreach ($runs as $k => $num_runs) {
+
+ // create n-rows
+ if (!mysqli_query($link, "DELETE FROM test")) {
+ $errors[] = sprintf("DELETE failed (%s) (converted code: %s): [%d] %s\n",
+ $type,
+ ($flag_original_code) ? 'no' : 'yes',
+ mysqli_errno($link), mysqli_error($link));
+ break 4;
+ }
+
+ $label = str_repeat('a', $len);
+ for ($i = 0; $i < $num_rows; $i++) {
+ $sql = sprintf("INSERT INTO test(id, label) VALUES (%d, '%s')", $i, $label);
+ if (!mysqli_query($link, $sql)) {
+ $errors[] = sprintf("INSERT failed (%s) (converted code: %s): [%d] %s\n",
+ $type,
+ ($flag_original_code) ? 'no' : 'yes',
+ mysqli_errno($link), mysqli_error($link));
+ break 5;
+ }
+ }
+
+ if (!$stmt = mysqli_stmt_init($link)) {
+ $errors[] = sprintf("stmt_init() failed (converted code: %s)\n",
+ ($flag_original_code) ? 'no' : 'yes');
+ break 4;
+ }
+ if (!mysqli_stmt_prepare($stmt, 'SELECT id, label FROM test ORDER BY id')) {
+ $errors[] = sprintf("stmt_prepare() failed (converted code: %s)\n",
+ ($flag_original_code) ? 'no' : 'yes');
+ break 4;
+ }
+ if (!mysqli_stmt_execute($stmt)) {
+ $errors[] = sprintf("stmt_execute() failed (converted code: %s)\n",
+ ($flag_original_code) ? 'no' : 'yes');
+ break 4;
+ }
+ $id = $label = null;
+ if (!mysqli_stmt_bind_result($stmt, $id, $label)) {
+ $errors[] = sprintf("stmt_bind_result() failed (converted code: %s)\n",
+ ($flag_original_code) ? 'no' : 'yes');
+ break 4;
+ }
+ if (!mysqli_stmt_store_result($stmt)) {
+ $errors[] = sprintf("stmt_store_result() failed (converted code: %s)\n",
+ ($flag_original_code) ? 'no' : 'yes');
+ break 4;
+ }
+
+ mt_srand();
+ $times[$num_rows . ' rows: ' . $num_runs . 'x ' . $type . ' overall'] =
microtime(true);
+ for ($i = 0; $i < $num_runs; $i++) {
+
+ $pos = mt_rand(0, $num_rows - 1);
+
+ $start = microtime(true);
+ mysqli_stmt_data_seek($stmt, $pos);
+ $times[$num_rows . ' rows: ' . $num_runs . 'x ' . $type . ' data_seek()'] +=
(microtime(true) - $start);
+
+ if (!mysqli_stmt_fetch($stmt)) {
+ $errors[] = sprintf("fetch() for %dth of %d rows failed (%s) (converted code:
%s): [%d] %s\n",
+ $pos, $num_rows, $type,
+ ($flag_original_code) ? 'no' : 'yes',
+ mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
+ break 5;
+ }
+
+ if ($id != $pos) {
+ $errors[] = sprintf("seek() + fetch() for %dth of %d rows did not work (%s)
(converted code: %s): [%d] %s\n",
+ $pos, $num_rows, $type,
+ ($flag_original_code) ? 'no' : 'yes',
+ mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
+ var_dump($id);
+ var_dump($pos);
+ break 5;
+ }
+
+ }
+ $times[$num_rows . ' rows: ' . $num_runs . 'x ' . $type . ' overall'] =
microtime(true) - $times[$num_rows . ' rows: ' . $num_runs . 'x ' . $type . ' overall'];
+
+ mysqli_stmt_close($stmt);
+ }
+ }
+
+ } // end foreach types
+
+
+ mysqli_close($link);
+
+} while (false);
+?>
\ No newline at end of file
Added: trunk/ext/mysqli/tests/bench/micro_benches/mysqli_stmt_data_seek_sequential.php
===================================================================
---
trunk/ext/mysqli/tests/bench/micro_benches/mysqli_stmt_data_seek_sequential.php 2007-03-20
15:05:27 UTC (rev 210)
+++
trunk/ext/mysqli/tests/bench/micro_benches/mysqli_stmt_data_seek_sequential.php 2007-03-20
15:09:00 UTC (rev 211)
@@ -0,0 +1,147 @@
+<?PHP
+$runs = array(10, 100);
+$rows = array(100, 1000);
+$types = array(
+ 16 => 'varchar(16)',
+ 32 => 'varchar(32)',
+ 64 => 'varchar(64)',
+ 128 => 'varchar(128)',
+ 256 => 'varchar(256)',
+ 512 => 'varchar(512)',
+ 1024 => 'varchar(1024)',
+ 2048 => 'varchar(2048)',
+ 4192 => 'varchar(4192)',
+ 8384 => 'varchar(8384)',
+ 16768 => 'varchar(16768)',
+ 33536 => 'varchar(33536)',
+ 65500 => 'varchar(65500)'
+
+ );
+foreach ($runs as $k => $num_runs) {
+ foreach ($rows as $k => $num_rows) {
+ foreach ($types as $len => $type) {
+ $times[$num_rows . ' rows: ' . $num_runs . 'x ' . $type . ' overall'] = 0;
+ $times[$num_rows . ' rows: ' . $num_runs . 'x ' . $type . ' data_seek()'] = 0;
+ }
+ }
+}
+$description = 'Connect, create n-rows with varchar(m), SELECT all, fetch them in reverse
order using o-times [$runs] mysqli_stmt_data_seek(n...0), close. n, m and o vary.';
+$errors = array();$errors = array();
+
+do {
+
+ if (!$link = mysqli_connect($host, $user, $passwd, $db, $port, $socket)) {
+ $errors[] = sprintf("Connect failure (converted code: %s)\n", ($flag_original_code) ?
'no' : 'yes');
+ break;
+ }
+
+ foreach ($types as $len => $type) {
+
+ if (!mysqli_query($link, "DROP TABLE IF EXISTS test")) {
+ $errors[] = sprintf("DROP TABLE failed (converted code: %s): [%d] %s\n",
+ ($flag_original_code) ? 'no' : 'yes',
+ mysqli_errno($link), mysqli_error($link));
+ break 2;
+ }
+
+ $sql = sprintf("CREATE TABLE test(id INT, label %s)", $type);
+ if (!mysqli_query($link, $sql)) {
+ $errors[] = sprintf("CREATE TABLE (%s) failed (converted code: %s): [%d] %s\n",
+ $sql,
+ ($flag_original_code) ? 'no' : 'yes',
+ mysqli_errno($link), mysqli_error($link));
+ break 2;
+ }
+
+ foreach ($rows as $k => $num_rows) {
+ foreach ($runs as $k => $num_runs) {
+
+ // create n-rows
+ if (!mysqli_query($link, "DELETE FROM test")) {
+ $errors[] = sprintf("DELETE failed (%s) (converted code: %s): [%d] %s\n",
+ $type,
+ ($flag_original_code) ? 'no' : 'yes',
+ mysqli_errno($link), mysqli_error($link));
+ break 4;
+ }
+
+ $label = str_repeat('a', $len);
+ for ($i = 0; $i < $num_rows; $i++) {
+ $sql = sprintf("INSERT INTO test(id, label) VALUES (%d, '%s')", $i, $label);
+ if (!mysqli_query($link, $sql)) {
+ $errors[] = sprintf("INSERT failed (%s) (converted code: %s): [%d] %s\n",
+ $type,
+ ($flag_original_code) ? 'no' : 'yes',
+ mysqli_errno($link), mysqli_error($link));
+ break 5;
+ }
+ }
+
+ if (!$stmt = mysqli_stmt_init($link)) {
+ $errors[] = sprintf("stmt_init() failed (converted code: %s)\n",
+ ($flag_original_code) ? 'no' : 'yes');
+ break 4;
+ }
+ if (!mysqli_stmt_prepare($stmt, 'SELECT id, label FROM test ORDER BY id')) {
+ $errors[] = sprintf("stmt_prepare() failed (converted code: %s)\n",
+ ($flag_original_code) ? 'no' : 'yes');
+ break 4;
+ }
+ if (!mysqli_stmt_execute($stmt)) {
+ $errors[] = sprintf("stmt_execute() failed (converted code: %s)\n",
+ ($flag_original_code) ? 'no' : 'yes');
+ break 4;
+ }
+ $id = $label = null;
+ if (!mysqli_stmt_bind_result($stmt, $id, $label)) {
+ $errors[] = sprintf("stmt_bind_result() failed (converted code: %s)\n",
+ ($flag_original_code) ? 'no' : 'yes');
+ break 4;
+ }
+ if (!mysqli_stmt_store_result($stmt)) {
+ $errors[] = sprintf("stmt_store_result() failed (converted code: %s)\n",
+ ($flag_original_code) ? 'no' : 'yes');
+ break 4;
+ }
+
+ $times[$num_rows . ' rows: ' . $num_runs . 'x ' . $type . ' overall'] =
microtime(true);
+ for ($i = 0; $i < $num_runs; $i++) {
+
+ $pos = $num_runs - $i - 1;
+
+ $start = microtime(true);
+ mysqli_stmt_data_seek($stmt, $pos);
+ $times[$num_rows . ' rows: ' . $num_runs . 'x ' . $type . ' data_seek()'] +=
(microtime(true) - $start);
+
+ if (!mysqli_stmt_fetch($stmt)) {
+ $errors[] = sprintf("fetch() for %dth of %d rows failed (%s) (converted code:
%s): [%d] %s\n",
+ $pos, $num_rows, $type,
+ ($flag_original_code) ? 'no' : 'yes',
+ mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
+ break 5;
+ }
+
+ if ($id != $pos) {
+ $errors[] = sprintf("seek() + fetch() for %dth of %d rows did not work (%s)
(converted code: %s): [%d] %s\n",
+ $pos, $num_rows, $type,
+ ($flag_original_code) ? 'no' : 'yes',
+ mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
+ var_dump($id);
+ var_dump($pos);
+ break 5;
+ }
+
+ }
+ $times[$num_rows . ' rows: ' . $num_runs . 'x ' . $type . ' overall'] =
microtime(true) - $times[$num_rows . ' rows: ' . $num_runs . 'x ' . $type . ' overall'];
+
+ mysqli_stmt_close($stmt);
+ }
+ }
+
+ } // end foreach types
+
+
+ mysqli_close($link);
+
+} while (false);
+?>
\ No newline at end of file
Added: trunk/ext/mysqli/tests/bench/micro_benches/mysqli_stmt_execute.php
===================================================================
--- trunk/ext/mysqli/tests/bench/micro_benches/mysqli_stmt_execute.php 2007-03-20 15:05:27
UTC (rev 210)
+++ trunk/ext/mysqli/tests/bench/micro_benches/mysqli_stmt_execute.php 2007-03-20 15:09:00
UTC (rev 211)
@@ -0,0 +1,71 @@
+<?PHP
+/* Config settings should go at the very beginning */
+$runs = 10000;
+
+// Set a description
+$description = 'Call stmt_execute() for "SELECT 1"';
+
+
+/*
+ This is a hash that stores the runtimes
+ It is dumped in all reports. The hash keys will be used as labels/descriptions.
+ $times['select()'] = 0.01; => shown in reports like 'select() : 0.01s'
+*/
+$times = array();
+/*
+ It's recommended to initialize the times hash with 0 values
+ for all entries. This often makes debugging easier.
+ Make sure you have one 'overall' entry in your list which
+ holds the 'entire runtime' of you test (e.g. create table + insert + select) and not
only
+ a fraction of it (e.g. select).
+*/
+$times['overall'] = 0;
+$times['execute'] = 0;
+
+/*
+ List of errors that happened during the test run. You should stop
+ the benchmark after the first error
+*/
+$errors = array();
+
+
+do {
+
+ $times['overall'] = microtime(true);
+
+ /*
+ Use this to connect to the database. The variables $host, ...
+ $socket and $flag_original_code are provided by the framework
+ */
+ if (!$link = mysqli_connect($host, $user, $passwd, $db, $port, $socket)) {
+ $errors[] = sprintf("Connect failure (converted code: %s)\n", ($flag_original_code) ?
'no' : 'yes');
+ break;
+ }
+
+ if (!$stmt = mysqli_stmt_init($link)) {
+ $errors[] = sprintf("stmt_init() (converted code: %s)\n", ($flag_original_code) ?
'no' : 'yes');
+ break;
+ }
+
+ if (!mysqli_stmt_prepare($stmt, "SELECT 1")) {
+ $errors[] = sprintf("stmt_prepare() (converted code: %s)\n", ($flag_original_code) ?
'no' : 'yes');
+ break;
+ }
+
+ $start = microtime(true);
+ for ($i = 0; $i < $runs; $i++) {
+ if (!@mysqli_stmt_execute($stmt)) {
+ $errors[] = sprintf("stmt_execute() (converted code: %s)\n", ($flag_original_code)
? 'no' : 'yes');
+ break 2;
+ }
+ mysqli_stmt_free_result($stmt);
+ }
+ $times['execute'] = microtime(true) - $start;
+
+
+ @mysqli_stmt_close($stmt);
+ mysqli_close($link);
+ $times['overall'] = (microtime(true) - $times['overall']);
+
+} while (false);
+?>
\ No newline at end of file
Added: trunk/ext/mysqli/tests/bench/micro_benches/mysqli_stmt_execute_insert_varchar.php
===================================================================
---
trunk/ext/mysqli/tests/bench/micro_benches/mysqli_stmt_execute_insert_varchar.php 2007-03-20
15:05:27 UTC (rev 210)
+++
trunk/ext/mysqli/tests/bench/micro_benches/mysqli_stmt_execute_insert_varchar.php 2007-03-20
15:09:00 UTC (rev 211)
@@ -0,0 +1,95 @@
+<?PHP
+$runs = array(1, 10, 100, 1000, 5000); // equals #rows
+$types = array(
+ 127 => 'varchar(127)',
+ 255 => 'varchar(255)',
+ 512 => 'varchar(512)',
+ 1024 => 'varchar(1024)',
+ 2048 => 'varchar(2048)',
+ 4096 => 'varchar(4096)',
+ 8192 => 'varchar(8192)',
+ 16384 => 'varchar(16384)',
+ 32768 => 'varchar(32768)',
+ );
+foreach ($runs as $k => $run) {
+ foreach ($types as $len => $type) {
+ $times['INSERT ' . $type . ' ' . $run . 'x = #rows query()'] = 0;
+ $times['INSERT ' . $type . ' ' . $run . 'x = #rows overall'] = 0;
+ }
+}
+$description = 'Connect, n-times INSERT varchar of size m, close. n and m vary.';
+$errors = array();
+
+function mysqli_query_insert($type, $len, $runs, $host, $user, $passwd, $db, $port,
$socket) {
+
+ $errors = $times = array();
+
+ foreach ($runs as $k => $run) {
+ $times['INSERT ' . $type . ' ' . $run . 'x = #rows overall'] = microtime(true);
+ do {
+ if (!$link = @mysqli_connect($host, $user, $passwd, $db, $port, $socket)) {
+ $errors[] = sprintf("INSERT %s %dx = #rows connect failure (original code =
%s)", $type, $run, ($flag_original_code) ? 'yes' : 'no');
+ break 2;
+ }
+ if (!mysqli_query($link, "DROP TABLE IF EXISTS test")) {
+ $errors[] = sprintf("INSERT %s %dx = #rows drop table failure (original code =
%s): [%d] %s", $type, $run, ($flag_original_code) ? 'yes' : 'no', mysqli_errno($link),
mysqli_error($link));
+ break 2;
+ }
+
+ if (!mysqli_query($link, sprintf("CREATE TABLE test(id INT NOT NULL AUTO_INCREMENT
PRIMARY KEY, label %s)", $type))) {
+ $errors[] = sprintf("INSERT %s %dx = #rows create table failure (original code =
%s): [%d] %s", $type, $run, ($flag_original_code) ? 'yes' : 'no', mysqli_errno($link),
mysqli_error($link));
+ break 2;
+ }
+
+ $label = '';
+ for ($i = 0; $i < $len; $i++)
+ $label .= chr(mt_rand(65, 90));
+
+ $start = microtime(true);
+ if (!$stmt = mysqli_stmt_init($link)) {
+ $error[] = sprintf("INSERT %s %dx = #rows mysqli_stmt_init() failed (original
code = %s): [%d] %s", $type, $run, ($flag_original_code) ? 'yes' : 'no',
mysqli_errno($link), mysqli_error($link));
+ break 2;
+ }
+ $ret = mysqli_stmt_prepare($stmt, "INSERT INTO test(id, label) VALUES (?, ?)");
+ $times['INSERT ' . $type . ' ' . $run . 'x = #rows stmt_init() + stmt_prepare()']
+= microtime(true) - $start;
+ if (!$ret) {
+ $error[] = sprintf("INSERT %s %dx = #rows mysqli_stmt_init() failed (original
code = %s): [%d] %s", $type, $run, ($flag_original_code) ? 'yes' : 'no',
mysqli_errno($link), mysqli_error($link));
+ break 2;
+ }
+
+ $start = microtime(true);
+ $ret = mysqli_stmt_bind_param($stmt, 'is', $i, $label);
+ $times['INSERT ' . $type . ' ' . $run . 'x = #rows stmt_bind_param()'] +=
microtime(true) - $start;
+ if (!$ret) {
+ $error[] = sprintf("INSERT %s %dx = #rows mysqli_stmt_bind_param failed
(original code = %s): [%d] %s", $type, $run, ($flag_original_code) ? 'yes' : 'no',
mysqli_errno($link), mysqli_error($link));
+ break 2;
+ }
+
+ for ($i = 1; $i <= $run; $i++) {
+ $start = microtime(true);
+ $ret = mysqli_stmt_execute($stmt);
+ $times['INSERT ' . $type . ' ' . $run . 'x = #rows stmt_execute()'] +=
microtime(true) - $start;
+ if (!$ret) {
+ $errors[] = sprintf("INSERT %s %dx = #rows stmt_execute failure (original code
= %s): [%d] %s", $type, $run, ($flag_original_code) ? 'yes' : 'no', mysqli_errno($link),
mysqli_error($link));
+ break 3;
+ }
+ }
+ mysqli_stmt_close($stmt);
+ mysqli_close($link);
+ } while (false);
+ $times['INSERT ' . $type . ' ' . $run . 'x = #rows overall'] = microtime(true) -
$times['INSERT ' . $type . ' ' . $run . 'x = #rows overall'];
+ }
+
+ return array($errors, $times);
+}
+
+
+ksort($types);
+foreach ($types as $len => $type) {
+ list ($errors, $tmp_times) = mysqli_query_insert($type, $len, $runs, $host, $user,
$passwd, $db, $port, $socket);
+ $times = array_merge($times, $tmp_times);
+ if (!empty($errors)) {
+ break;
+ }
+}
+?>
\ No newline at end of file
Added:
trunk/ext/mysqli/tests/bench/micro_benches/mysqli_stmt_execute_select_varchar_buffered.php
===================================================================
---
trunk/ext/mysqli/tests/bench/micro_benches/mysqli_stmt_execute_select_varchar_buffered.php 2007-03-20
15:05:27 UTC (rev 210)
+++
trunk/ext/mysqli/tests/bench/micro_benches/mysqli_stmt_execute_select_varchar_buffered.php 2007-03-20
15:09:00 UTC (rev 211)
@@ -0,0 +1,155 @@
+<?PHP
+$runs = array(10, 100);
+$rows = array(100, 1000);
+$types = array(
+ 127 => 'varchar(127)',
+ 255 => 'varchar(255)',
+ 512 => 'varchar(512)',
+ 1024 => 'varchar(1024)',
+ 2048 => 'varchar(2048)',
+ 4096 => 'varchar(4096)',
+ 8192 => 'varchar(8192)',
+ 16384 => 'varchar(16384)',
+ 32768 => 'varchar(32768)',
+ 65000 => 'varchar(65000)',
+ );
+$times = array();
+foreach ($rows as $k => $num_rows) {
+ foreach ($runs as $k => $run) {
+ foreach ($types as $len => $type) {
+ $times[$num_rows . ' rows: SELECT ' . $type . ' ' . $run . 'x query()'] = 0;
+ $times[$num_rows . ' rows: SELECT ' . $type . ' ' . $run . 'x overall'] = 0;
+ $times[$num_rows . ' rows: SELECT ' . $type . ' ' . $run . 'x fetch_assoc()'] = 0;
+ }
+ }
+}
+$description = 'Connect, create n rows with varchar of size m, o-times SELECT all rows
(unbuffered), close. n, m, o vary.';
+$errors = array();
+
+function mysqli_query_select_varchar_unbuffered($type, $len, $runs, $rows, $host, $user,
$passwd, $db, $port, $socket, $flag_original_code) {
+
+ $errors = $times = array();
+
+ foreach ($rows as $k => $num_rows) {
+
+ foreach ($runs as $k => $run) {
+
+ $times[$num_rows . ' rows: SELECT ' . $type . ' ' . $run . 'x overall'] =
microtime(true);
+
+ do {
+ if (!$link = @mysqli_connect($host, $user, $passwd, $db, $port, $socket)) {
+ $errors[] = sprintf("%d rows: SELECT %s %dx connect failure (original code =
%s)",
+ $num_rows, $type, $run, ($flag_original_code) ? 'yes' :
'no');
+ break 3;
+ }
+ if (!mysqli_query($link, "DROP TABLE IF EXISTS test")) {
+ $errors[] = sprintf("%d rows: SELECT %s %dx drop table failure (original code =
%s): [%d] %s",
+ $num_rows, $type, $run, ($flag_original_code) ? 'yes' :
'no', mysqli_errno($link), mysqli_error($link));
+ break 3;
+ }
+
+ if (!mysqli_query($link, sprintf("CREATE TABLE test(id INT NOT NULL
AUTO_INCREMENT PRIMARY KEY, label %s)", $type))) {
+ $errors[] = sprintf("%d rows: SELECT %s %dx create table failure (original code
= %s): [%d] %s",
+ $num_rows, $type, $run, ($flag_original_code) ?
'yes' : 'no', mysqli_errno($link), mysqli_error($link));
+ break 3;
+ }
+
+ $label = '';
+ for ($i = 0; $i < $len; $i++)
+ $label .= chr(mt_rand(65, 90));
+
+ if (!$stmt = mysqli_stmt_init($link)) {
+ $errors[] = sprintf("%d rows: SELECT %s %dx stmt_init() for INSERT failed
(original code = %s): [%d] %s",
+ $num_rows, $type, $run, ($flag_original_code) ?
'yes' : 'no', mysqli_errno($link), mysqli_error($link));
+ break 3;
+ }
+ if (!mysqli_stmt_prepare($stmt, "INSERT INTO test(id, label) VALUES (?, ?)")) {
+ $errors[] = sprintf("%d rows: SELECT %s %dx stmt_prepare() for INSERT failed
(original code = %s): [%d] %s",
+ $num_rows, $type, $run, ($flag_original_code) ?
'yes' : 'no', mysqli_errno($link), mysqli_error($link));
+ break 3;
+ }
+ if (!mysqli_stmt_bind_param($stmt, "is", $i, $label)) {
+ $errors[] = sprintf("%d rows: SELECT %s %dx stmt_bind_param() for INSERT
failed (original code = %s): [%d] %s",
+ $num_rows, $type, $run, ($flag_original_code) ?
'yes' : 'no', mysqli_errno($link), mysqli_error($link));
+ break 3;
+ }
+
+ for ($i = 1; $i <= $num_rows; $i++) {
+ if (!mysqli_stmt_execute($stmt)) {
+ $errors[] = sprintf("%d rows: SELECT %s %dx insert failure (original code =
%s): [%d] %s",
+ $num_rows, $type, $run, ($flag_original_code) ? 'yes' :
'no', mysqli_errno($link), mysqli_error($link));
+ break 4;
+ }
+ }
+ mysqli_stmt_close($stmt);
+
+
+ for ($i = 0; $i < $run; $i++) {
+
+ if (!$stmt = mysqli_stmt_init($link)) {
+ $errors[] = sprintf("%d rows: SELECT %s %dx stmt_init() for SELECT failed
(original code = %s): [%d] %s",
+ $num_rows, $type, $run, ($flag_original_code) ?
'yes' : 'no', mysqli_errno($link), mysqli_error($link));
+ break 4;
+ }
+ if (!mysqli_stmt_prepare($stmt, "SELECT id, label FROM test")) {
+ $errors[] = sprintf("%d rows: SELECT %s %dx stmt_prepare() for SELECT failed
(original code = %s): [%d] %s",
+ $num_rows, $type, $run, ($flag_original_code) ?
'yes' : 'no', mysqli_errno($link), mysqli_error($link));
+ break 4;
+ }
+ $start = microtime(true);
+ $ret = mysqli_stmt_execute($stmt);
+ $times[$num_rows . ' rows: SELECT ' . $type . ' ' . $run . 'x stmt_execute()']
+= (microtime(true) - $start);
+ if (!$ret) {
+ $errors[] = sprintf("%d rows: SELECT %s %dx insert failure (original code =
%s): [%d] %s",
+ $rows, $type, $run, ($flag_original_code) ? 'yes' : 'no',
mysqli_errno($link), mysqli_error($link));
+ break 4;
+ }
+
+ $start = microtime(true);
+ $ret = mysqli_stmt_store_result($stmt);
+ $times[$num_rows . ' rows: SELECT ' . $type . ' ' . $run . 'x
stmt_store_result()'] += (microtime(true) - $start);
+ if (!$ret) {
+ $errors[] = sprintf("%d rows: SELECT %s %dx insert failure (original code =
%s): [%d] %s",
+ $rows, $type, $run, ($flag_original_code) ? 'yes' : 'no',
mysqli_errno($link), mysqli_error($link));
+ break 4;
+ }
+
+ if (!mysqli_stmt_bind_result($stmt, $id2, $label2)) {
+ $errors[] = sprintf("%d rows: SELECT %s %dx stmt_prepare() for SELECT failed
(original code = %s): [%d] %s",
+ $num_rows, $type, $run, ($flag_original_code) ?
'yes' : 'no', mysqli_errno($link), mysqli_error($link));
+ break 4;
+ }
+
+ $start = microtime(true);
+ while (mysqli_stmt_fetch($stmt))
+ ;
+ $times[$num_rows . ' rows: SELECT ' . $type . ' ' . $run . 'x stmt_fetch()'] +=
(microtime(true) - $start);
+ mysqli_stmt_close($stmt);
+
+ }
+
+ mysqli_close($link);
+
+ } while (false);
+
+ $times[$num_rows . ' rows: SELECT ' . $type . ' ' . $run . 'x overall'] =
microtime(true) - $times[$num_rows . ' rows: SELECT ' . $type . ' ' . $run . 'x
overall'];
+
+ }
+
+ }
+
+ return array($errors, $times);
+}
+
+
+foreach ($types as $len => $type) {
+ list ($errors, $tmp_times) = mysqli_query_select_varchar_unbuffered($type, $len,
$runs, $rows, $host, $user, $passwd, $db, $port, $socket, $flag_original_code);
+ $times = array_merge($times, $tmp_times);
+ if (!empty($errors)) {
+ break;
+ }
+}
+
+// sort by labels
+ksort($times);
+?>
Added:
trunk/ext/mysqli/tests/bench/micro_benches/mysqli_stmt_execute_select_varchar_unbuffered.php
===================================================================
---
trunk/ext/mysqli/tests/bench/micro_benches/mysqli_stmt_execute_select_varchar_unbuffered.php 2007-03-20
15:05:27 UTC (rev 210)
+++
trunk/ext/mysqli/tests/bench/micro_benches/mysqli_stmt_execute_select_varchar_unbuffered.php 2007-03-20
15:09:00 UTC (rev 211)
@@ -0,0 +1,147 @@
+<?PHP
+$runs = array(10, 100);
+$rows = array(100, 1000);
+$types = array(
+ 127 => 'varchar(127)',
+ 255 => 'varchar(255)',
+ 512 => 'varchar(512)',
+ 1024 => 'varchar(1024)',
+ 2048 => 'varchar(2048)',
+ 4096 => 'varchar(4096)',
+ 8192 => 'varchar(8192)',
+ 16384 => 'varchar(16384)',
+ 32768 => 'varchar(32768)',
+ 65000 => 'varchar(65000)',
+ );
+$times = array();
+foreach ($rows as $k => $num_rows) {
+ foreach ($runs as $k => $run) {
+ foreach ($types as $len => $type) {
+ $times[$num_rows . ' rows: SELECT ' . $type . ' ' . $run . 'x query()'] = 0;
+ $times[$num_rows . ' rows: SELECT ' . $type . ' ' . $run . 'x overall'] = 0;
+ $times[$num_rows . ' rows: SELECT ' . $type . ' ' . $run . 'x fetch_assoc()'] = 0;
+ }
+ }
+}
+$description = 'Connect, create n rows with varchar of size m, o-times SELECT all rows
(unbuffered), close. n, m, o vary.';
+$errors = array();
+
+function mysqli_query_select_varchar_unbuffered($type, $len, $runs, $rows, $host, $user,
$passwd, $db, $port, $socket, $flag_original_code) {
+
+ $errors = $times = array();
+
+ foreach ($rows as $k => $num_rows) {
+
+ foreach ($runs as $k => $run) {
+
+ $times[$num_rows . ' rows: SELECT ' . $type . ' ' . $run . 'x overall'] =
microtime(true);
+
+ do {
+ if (!$link = @mysqli_connect($host, $user, $passwd, $db, $port, $socket)) {
+ $errors[] = sprintf("%d rows: SELECT %s %dx connect failure (original code =
%s)",
+ $num_rows, $type, $run, ($flag_original_code) ? 'yes' :
'no');
+ break 3;
+ }
+ if (!mysqli_query($link, "DROP TABLE IF EXISTS test")) {
+ $errors[] = sprintf("%d rows: SELECT %s %dx drop table failure (original code =
%s): [%d] %s",
+ $num_rows, $type, $run, ($flag_original_code) ? 'yes' :
'no', mysqli_errno($link), mysqli_error($link));
+ break 3;
+ }
+
+ if (!mysqli_query($link, sprintf("CREATE TABLE test(id INT NOT NULL
AUTO_INCREMENT PRIMARY KEY, label %s)", $type))) {
+ $errors[] = sprintf("%d rows: SELECT %s %dx create table failure (original code
= %s): [%d] %s",
+ $num_rows, $type, $run, ($flag_original_code) ?
'yes' : 'no', mysqli_errno($link), mysqli_error($link));
+ break 3;
+ }
+
+ $label = '';
+ for ($i = 0; $i < $len; $i++)
+ $label .= chr(mt_rand(65, 90));
+
+ if (!$stmt = mysqli_stmt_init($link)) {
+ $errors[] = sprintf("%d rows: SELECT %s %dx stmt_init() for INSERT failed
(original code = %s): [%d] %s",
+ $num_rows, $type, $run, ($flag_original_code) ?
'yes' : 'no', mysqli_errno($link), mysqli_error($link));
+ break 3;
+ }
+ if (!mysqli_stmt_prepare($stmt, "INSERT INTO test(id, label) VALUES (?, ?)")) {
+ $errors[] = sprintf("%d rows: SELECT %s %dx stmt_prepare() for INSERT failed
(original code = %s): [%d] %s",
+ $num_rows, $type, $run, ($flag_original_code) ?
'yes' : 'no', mysqli_errno($link), mysqli_error($link));
+ break 3;
+ }
+ if (!mysqli_stmt_bind_param($stmt, "is", $i, $label)) {
+ $errors[] = sprintf("%d rows: SELECT %s %dx stmt_bind_param() for INSERT
failed (original code = %s): [%d] %s",
+ $num_rows, $type, $run, ($flag_original_code) ?
'yes' : 'no', mysqli_errno($link), mysqli_error($link));
+ break 3;
+ }
+
+ for ($i = 1; $i <= $num_rows; $i++) {
+ if (!mysqli_stmt_execute($stmt)) {
+ $errors[] = sprintf("%d - $i rows: SELECT %s %dx insert failure (original
code = %s): [%d] %s",
+ $num_rows, $type, $run, ($flag_original_code) ? 'yes' :
'no', mysqli_errno($link), mysqli_error($link));
+ break 4;
+ }
+ }
+ mysqli_stmt_close($stmt);
+
+ for ($i = 0; $i < $run; $i++) {
+
+ if (!$stmt = mysqli_stmt_init($link)) {
+ $errors[] = sprintf("%d rows: SELECT %s %dx stmt_init() for SELECT failed
(original code = %s): [%d] %s", $num_rows, $type,
$run, ($flag_original_code) ? 'yes' : 'no', mysqli_errno($link), mysqli_error($link));
+ break 4;
+ }
+ if (!mysqli_stmt_prepare($stmt, "SELECT id, label FROM test")) {
+ $errors[] = sprintf("%d rows: SELECT %s %dx stmt_prepare() for SELECT failed
(original code = %s): [%d] %s",
+ $num_rows, $type, $run, ($flag_original_code) ?
'yes' : 'no', mysqli_errno($link), mysqli_error($link));
+ break 4;
+ }
+
+ $start = microtime(true);
+ $ret = mysqli_stmt_execute($stmt);
+ $times[$num_rows . ' rows: SELECT ' . $type . ' ' . $run . 'x stmt_execute()']
+= (microtime(true) - $start);
+
+ if (!$ret) {
+ $errors[] = sprintf("%d rows: SELECT %s %dx stmt_execute() SELECT failure
(original code = %s): [%d] %s",
+ $rows, $type, $run, ($flag_original_code) ? 'yes' : 'no',
mysqli_errno($link), mysqli_error($link));
+ break 4;
+ }
+
+ $id2 = $label2 = null;
+ if (!mysqli_stmt_bind_result($stmt, $id2, $label2)) {
+ $errors[] = sprintf("%d rows: SELECT %s %dx stmt_prepare() for SELECT failed
(original code = %s): [%d] %s",
+ $num_rows, $type, $run, ($flag_original_code) ?
'yes' : 'no', mysqli_errno($link), mysqli_error($link));
+ break 4;
+ }
+
+ $start = microtime(true);
+ while (mysqli_stmt_fetch($stmt))
+ ;
+ $times[$num_rows . ' rows: SELECT ' . $type . ' ' . $run . 'x stmt_fetch()'] +=
(microtime(true) - $start);
+ mysqli_stmt_close($stmt);
+
+ }
+
+ mysqli_close($link);
+
+ } while (false);
+
+ $times[$num_rows . ' rows: SELECT ' . $type . ' ' . $run . 'x overall'] =
microtime(true) - $times[$num_rows . ' rows: SELECT ' . $type . ' ' . $run . 'x
overall'];
+
+ }
+
+ }
+
+ return array($errors, $times);
+}
+
+
+foreach ($types as $len => $type) {
+ list ($errors, $tmp_times) = mysqli_query_select_varchar_unbuffered($type, $len,
$runs, $rows, $host, $user, $passwd, $db, $port, $socket, $flag_original_code);
+ $times = array_merge($times, $tmp_times);
+ if (!empty($errors)) {
+ break;
+ }
+}
+
+// sort by labels
+ksort($times);
+?>
Added:
trunk/ext/mysqli/tests/bench/micro_benches/mysqli_stmt_fetch_many_columns_unbuffered.php
===================================================================
---
trunk/ext/mysqli/tests/bench/micro_benches/mysqli_stmt_fetch_many_columns_unbuffered.php 2007-03-20
15:05:27 UTC (rev 210)
+++
trunk/ext/mysqli/tests/bench/micro_benches/mysqli_stmt_fetch_many_columns_unbuffered.php 2007-03-20
15:09:00 UTC (rev 211)
@@ -0,0 +1,143 @@
+<?PHP
+// measured in KB, that means 1 = 1024 bytes
+$columns = array(1, 3, 5, 10, 15, 20, 30, 40, 50, 100, 300, 500);
+$column_types = array(
+ array("len" => 1, "name" => "c_tinyint", "type" => "TINYINT",
"value" => 1),
+ array("len" => 2, "name" => "c_smallint", "type" =>
"SMALLINT", "value" => 1),
+ array("len" => 200, "name" => "c_varchar_199", "type" =>
"varchar(199)", "value" =>
"0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678"),
+ array("len" => 3, "name" => "c_mediumint", "type" =>
"MEDIUMINT", "value" => 1),
+ array("len" => 20, "name" => "c_varchar_19", "type" =>
"varchar(19)", "value" => "0123456789012345678"),
+ array("len" => 4, "name" => "c_int", "type" => "INT", "value"
=> 1),
+ array("len" => 8, "name" => "c_bigint", "type" => "BIGINT",
"value" => 1),
+ array("len" => 50, "name" => "c_varchar_49", "type" =>
"varchar(49)", "value" => "0123456789012345678901234567890123456789012345678"),
+ array("len" => 4, "name" => "c_float_24", "type" =>
"FLOAT(24)", "value" => 1),
+ array("len" => 150, "name" => "c_varchar_149", "type" =>
"varchar(149)", "value" =>
"1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678"),
+ array("len" => 8, "name" => "c_float_25", "type" =>
"FLOAT(25)", "value" => 1),
+ array("len" => 4, "name" => "c_float", "type" => "FLOAT",
"value" => 1),
+ array("len" => 8, "name" => "c_double", "type" => "DOUBLE",
"value" => 1),
+ array("len" => 100, "name" => "c_varchar_99", "type" =>
"varchar(99)", "value" =>
"012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678"),
+ array("len" => 3, "name" => "c_date", "type" => "DATE",
"value" => "2007-01-17"),
+ array("len" => 8, "name" => "c_datetime", "type" =>
"DATETIME", "value" => "2007-01-17 11:53:00"),
+ array("len" => 4, "name" => "c_timestamp", "type" =>
"TIMESTAMP", "value" => "2007-01-17 11:54:00"),
+ array("len" => 3, "name" => "c_time", "type" => "TIME",
"value" => "11:54:00"),
+ array("len" => 1, "name" => "c_year", "type" => "YEAR",
"value" => "2007"),
+ array("len" => 10, "name" => "c_char_10", "type" =>
"CHAR(10)", "value" => "0123456789"),
+ array("len" => 1, "name" => "c_enum", "type" => "ENUM('true',
'false')", "value" => "true"),
+ // let's assume latin1
+ array("len" => 300, "name" => "c_varchar_99", "type" =>
"varchar(298)", "value" =>
"0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567"),
+ );
+$rows = array(2000);
+
+
+foreach ($rows as $k => $num_rows) {
+ foreach ($columns as $k => $num_columns) {
+
+ $num_column_types = count($column_types);
+ $total_len = 0;
+ for ($i = 0; $i < $num_columns; $i++) {
+ $total_len += $column_types[$i % $num_column_types]['len'];
+ }
+ $times[$num_rows . ' row[s]: ' . $num_columns . ' column[s] (' . $total_len . '
bytes) overall'] = 0;
+ $times[$num_rows . ' row[s]: ' . $num_columns . ' column[s] (' . $total_len . '
bytes) fetch()'] = 0;
+ }
+}
+$description = 'Connect, create n-rows with one m-columns of different types, SELECT all
(buffered), close. n and m vary.';
+$errors = array();
+
+do {
+
+ if (!$link = mysqli_connect($host, $user, $passwd, $db, $port, $socket)) {
+ $errors[] = sprintf("Connect failure (converted code: %s)\n", ($flag_original_code) ?
'no' : 'yes');
+ break;
+ }
+
+ foreach ($rows as $k => $num_rows) {
+
+ foreach ($columns as $k => $num_columns) {
+
+ if (!mysqli_query($link, "DROP TABLE IF EXISTS test")) {
+ $errors[] = sprintf("DROP TABLE failed (converted code: %s): [%d] %s\n",
+ ($flag_original_code) ? 'no' : 'yes',
+ mysqli_errno($link), mysqli_error($link));
+ break 3;
+ }
+
+ $num_column_types = count($column_types);
+ $total_len = 0;
+ $column_names = $column_defs = $column_values = '';
+ for ($i = 0; $i < $num_columns; $i++) {
+ $index = $i % $num_column_types;
+ $total_len += $column_types[$index]['len'];
+ $column_names .= sprintf("%s_%d, ", $column_types[$index]['name'], $i);
+ $column_defs .= sprintf("%s_%d %s, ", $column_types[$index]['name'], $i,
$column_types[$index]['type']);
+ $column_values .= sprintf("%s%s%s, ",
+ (is_string($column_types[$index]['value'])) ? '"' : '',
+ $column_types[$index]['value'],
+ (is_string($column_types[$index]['value'])) ? '"' : ''
+ );
+ }
+ $last_column = sprintf("%s_%d", $column_types[$index]['name'], $i - 1);
+ $last_value = $column_types[$index]['value'];
+
+ $sql = sprintf("CREATE TABLE test(%s)", substr($column_defs, 0, -2));
+ if (!mysqli_query($link, $sql)) {
+ $errors[] = sprintf("%s failed (converted code: %s): [%d] %s\n",
+ $sql,
+ ($flag_original_code) ? 'no' : 'yes',
+ mysqli_errno($link), mysqli_error($link));
+ break 3;
+ }
+
+ $sql = sprintf("INSERT INTO test(%s) VALUES (%s)", substr($column_names, 0, -2),
substr($column_values, 0, -2));
+ for ($i = 0; $i < $num_rows; $i++) {
+ if (!mysqli_query($link, $sql)) {
+ $errors[] = sprintf("%s failed (converted code: %s): [%d] %s\n",
+ $sql,
+ ($flag_original_code) ? 'no' : 'yes',
+ mysqli_errno($link), mysqli_error($link));
+ break 4;
+ }
+ }
+
+ $times[$num_rows . ' row[s]: ' . $num_columns . ' column[s] (' . $total_len . '
bytes) overall'] = microtime(true);
+
+ if (!$stmt = mysqli_stmt_init($link)) {
+ $errors[] = sprintf("stmt_init() failed (converted code: %s)\n",
+ ($flag_original_code) ? 'no' : 'yes');
+ break 3;
+ }
+ if (!mysqli_stmt_prepare($stmt, 'SELECT * FROM test')) {
+ $errors[] = sprintf("stmt_prepare() failed (converted code: %s)\n",
+ ($flag_original_code) ? 'no' : 'yes');
+ break 3;
+ }
+ if (!mysqli_stmt_execute($stmt)) {
+ $errors[] = sprintf("stmt_execute() failed (converted code: %s)\n",
+ ($flag_original_code) ? 'no' : 'yes');
+ break 3;
+ }
+
+ $row = array();
+ $cmd = 'mysqli_stmt_bind_result($stmt, ';
+ for ($i = 0; $i < $num_columns; $i++)
+ $cmd .= sprintf('$row[%d], ', $i);
+
+ $cmd = (substr($cmd, 0, -2) . ');');
+ eval($cmd);
+
+ $start = microtime(true);
+ while (mysqli_stmt_fetch($stmt))
+ ;
+ $times[$num_rows . ' row[s]: ' . $num_columns . ' column[s] (' . $total_len . '
bytes) fetch()'] += (microtime(true) - $start);
+
+ mysqli_stmt_close($stmt);
+ $times[$num_rows . ' row[s]: ' . $num_columns . ' column[s] (' . $total_len . '
bytes) overall'] = microtime(true) - $times[$num_rows . ' row[s]: ' . $num_columns . '
column[s] (' . $total_len . ' bytes) overall'];
+
+ }
+ }
+
+
+ mysqli_close($link);
+
+} while (false);
+?>
\ No newline at end of file
| Thread |
|---|
| • PHP mysqlnd svn commit: r211 - trunk/ext/mysqli/tests/bench/micro_benches | uwendel | 20 Mar |