name = $name; $this->dbi = $dbi; $this->usr = $usr; $this->passwd = $passwd; } public function getBenchmarkName() { return $this->name; } public function init() { $this->db = MFDB::newInstance($this->dbi,$this->usr,$this->passwd); } public function benchCreateDropTables() { $tableinfo = $this->generateTableDef(); for ($i = 0; $i < 10; $i++) { $start = microtime(true); $this->db->createTable($tableinfo); $stop = microtime(true); $create[] = $stop - $start; $start = microtime(true); $this->db->dropTable($this->testtablename); $stop = microtime(true); $drop[] = $stop - $start; } $times['create'] = array_avg($create); $times['drop'] = array_avg($drop); return $times; } public function benchInsertData() { $tableinfo = $this->generateTableDef(); $this->db->createTable($tableinfo); $this->rowtestnum = 1; $timing = array(); for ($i = 0; $i < 2000; $i++) { $data = $this->generateDataRow(); $start = microtime(true); $this->db->table($this->testtablename)->insert($data); $stop = microtime(true); $timing[] = $stop - $start; } $this->db->dropTable($this->testtablename); $times['insert_obj'] = array_avg($timing); return $times; } public function benchSelectPKDataTable() { $tableinfo = $this->generateTableDef(); $this->db->createTable($tableinfo); $this->rowtestnum = 1; for ($i = 0; $i < 2000; $i++) { $data = $this->generateDataRow(); $this->db->table($this->testtablename)->insert($data); } $timing = array(); for ($i = 0; $i < 1000; $i++) { $selRow = ($i*5) % 1900; $start = microtime(true); $result = $this->db->table($this->testtablename)->select(array('colIndex' => $selRow)); $data = $result->fetchRow(); $result->close(); $stop = microtime(true); unset($result); $timing[] = $stop - $start; } $this->db->dropTable($this->testtablename); $times['table_select_row'] = array_avg($timing); $this->db->createTable($tableinfo); $this->rowtestnum = 1; for ($i = 0; $i < 2000; $i++) { $data = $this->generateDataRow(); $this->db->table($this->testtablename)->insert($data); } $timing = array(); for ($i = 0; $i < 1000; $i++) { $selRow = ($i*5) % 1900; $start = microtime(true); $result = $this->db->table($this->testtablename)->select(array('colIndex' => $selRow)); $data = $result->fetchObject(); $result->close(); $stop = microtime(true); unset($result); $timing[] = $stop - $start; } $this->db->dropTable($this->testtablename); $times['table_select_obj'] = array_avg($timing); return $times; } public function benchSelectDataTable() { $tableinfo = $this->generateTableDef(); $this->db->createTable($tableinfo); $this->rowtestnum = 0; for ($i = 0; $i < 2000; $i++) { $data = $this->generateDataRow(); $this->db->table($this->testtablename)->insert($data); } $timing = array(); for ($i = 0; $i < 1000; $i++) { $selRow = ($i*5) % 1900; $start = microtime(true); $result = $this->db->table($this->testtablename)->select(array('col1' => $selRow)); $data = $result->fetchRow(); $result->close(); $stop = microtime(true); unset($result); $timing[] = $stop - $start; } $this->db->dropTable($this->testtablename); $times['table_select_row'] = array_avg($timing); $this->db->createTable($tableinfo); $this->rowtestnum = 0; for ($i = 0; $i < 2000; $i++) { $data = $this->generateDataRow(); $this->db->table($this->testtablename)->insert($data); } $timing = array(); for ($i = 0; $i < 1000; $i++) { $selRow = ($i*5) % 1900; $start = microtime(true); $result = $this->db->table($this->testtablename)->select(array('col1' => $selRow)); $data = $result->fetchObject(); $result->close(); $stop = microtime(true); unset($result); $timing[] = $stop - $start; } $this->db->dropTable($this->testtablename); $times['table_select_obj'] = array_avg($timing); return $times; } public function benchSelectDataTablePrepared() { $tableinfo = $this->generateTableDef(); $this->db->createTable($tableinfo); $this->rowtestnum = 0; for ($i = 0; $i < 2000; $i++) { $data = $this->generateDataRow(); $this->db->table($this->testtablename)->insert($data); } $tblname = $this->db->escapeTableName($this->testtablename); $timing = array(); for ($i = 0; $i < 1000; $i++) { $selRow = ($i*5) % 1900; $start = microtime(true); $stmt = $this->db->prepareStatement("SELECT * FROM {$tblname} WHERE col1=?"); $stmt->execute(array($selRow)); $data = $stmt->fetchRow(); $stmt->close(); $stop = microtime(true); unset($stmt); $timing[] = $stop - $start; } $this->db->dropTable($this->testtablename); $times['table_select_row_prep_allways'] = array_avg($timing); $this->db->createTable($tableinfo); $this->rowtestnum = 0; for ($i = 0; $i < 2000; $i++) { $data = $this->generateDataRow(); $this->db->table($this->testtablename)->insert($data); } $timing = array(); $stmt = $this->db->prepareStatement("SELECT * FROM {$tblname} WHERE col1=?"); for ($i = 0; $i < 1000; $i++) { $selRow = ($i*5) % 1900; $start = microtime(true); $stmt->execute(array($selRow)); $data = $stmt->fetchRow(); $stmt->free(); $stop = microtime(true); $timing[] = $stop - $start; } $stmt->close(); unset($stmt); $this->db->dropTable($this->testtablename); $times['table_select_row_prep_once'] = array_avg($timing); return $times; } public function cleanup() { if (is_object($this->db)) { try { if ($this->db->tableExists($this->testtablename)) $this->db->dropTable($this->testtablename); } catch (Exception $e) {} $this->db->close(); } } private function generateTableDef() { $table = new MFDBTableInfo($this->testtablename); $table->addColumn(new MFDBColumnInfo('colIndex',MFDBColumnInfo::TYPE_INT,-1,array(MFDBColumnInfo::P_AUTONUM))); $table->addColumn(new MFDBColumnInfo('col1',MFDBColumnInfo::TYPE_INT,-1)); $table->addColumn(new MFDBColumnInfo('col2',MFDBColumnInfo::TYPE_DOUBLE,-1)); $table->addColumn(new MFDBColumnInfo('col3',MFDBColumnInfo::TYPE_CHAR,20)); $table->addColumn(new MFDBColumnInfo('col4',MFDBColumnInfo::TYPE_BOOLEAN,-1)); $table->addColumn(new MFDBColumnInfo('col5',MFDBColumnInfo::TYPE_CHAR,25,array(),NULL,NULL,'abc')); $table->addColumn(new MFDBColumnInfo('coltiny',MFDBColumnInfo::TYPE_TINY,-1,array(MFDBColumnInfo::P_ALLOW_NULL))); $table->addColumn(new MFDBColumnInfo('colshort',MFDBColumnInfo::TYPE_SHORT,-1,array(MFDBColumnInfo::P_ALLOW_NULL))); $table->addColumn(new MFDBColumnInfo('colint',MFDBColumnInfo::TYPE_INT,-1,array(MFDBColumnInfo::P_ALLOW_NULL))); $table->addColumn(new MFDBColumnInfo('collong',MFDBColumnInfo::TYPE_LONG,-1,array(MFDBColumnInfo::P_ALLOW_NULL))); $table->addColumn(new MFDBColumnInfo('colreal',MFDBColumnInfo::TYPE_FLOAT,-1,array(MFDBColumnInfo::P_ALLOW_NULL))); $table->addColumn(new MFDBColumnInfo('coldouble',MFDBColumnInfo::TYPE_DOUBLE,-1,array(MFDBColumnInfo::P_ALLOW_NULL))); $table->addColumn(new MFDBColumnInfo('coldec',MFDBColumnInfo::TYPE_DECIMAL,array(2,2),array(MFDBColumnInfo::P_ALLOW_NULL))); $table->addColumn(new MFDBColumnInfo('colchar',MFDBColumnInfo::TYPE_CHAR,64,array(MFDBColumnInfo::P_ALLOW_NULL))); $table->addColumn(new MFDBColumnInfo('colvchar',MFDBColumnInfo::TYPE_VCHAR,64,array(MFDBColumnInfo::P_ALLOW_NULL))); $table->addColumn(new MFDBColumnInfo('coltext',MFDBColumnInfo::TYPE_TEXT,-1,array(MFDBColumnInfo::P_ALLOW_NULL))); $table->addColumn(new MFDBColumnInfo('colbin',MFDBColumnInfo::TYPE_BINARY,64,array(MFDBColumnInfo::P_ALLOW_NULL))); $table->addColumn(new MFDBColumnInfo('colblob',MFDBColumnInfo::TYPE_BLOB,-1,array(MFDBColumnInfo::P_ALLOW_NULL))); $table->addColumn(new MFDBColumnInfo('coldate',MFDBColumnInfo::TYPE_DATE,-1,array(MFDBColumnInfo::P_ALLOW_NULL))); $table->addColumn(new MFDBColumnInfo('coldatetime',MFDBColumnInfo::TYPE_DATETIME,-1,array(MFDBColumnInfo::P_ALLOW_NULL))); $table->addColumn(new MFDBColumnInfo('colenum',MFDBColumnInfo::TYPE_ENUM,-1,array(MFDBColumnInfo::P_ALLOW_NULL,'values(a,b,c,d)'))); $table->setPrimary(array('colIndex')); $table->setIndex('test',array('col2', 'col3')); return $table; } private $rowtestnum = 100; private function generateDataRow() { $row = new stdClass(); $row->colIndex = MFDBSQLFunction::fDefault(); $row->col1 = $this->rowtestnum++; $row->col2 = 1.23; $row->col3 = 'Char4711'; $row->col4 = false; $row->col5 = 'Char 54321'; $row->coltiny = 123; $row->colshort = 12341; $row->colint = 1234123412; $row->collong = 123412341234; $row->colreal = 0.11; $row->coldouble = 0.1111; $row->coldec = 0; $row->colchar = '12341gfhd56'; $row->colvchar = '356sdft'; $row->coltext = 'w45s5w45w3'; $row->colbin = NULL; $row->colblob = NULL; $row->coldate = NULL; $row->coldatetime = new DateTime(); $row->colenum = 'a'; return $row; } }