\n"); } $CHARS = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890!@#$%^&*()_- {}][;:,.'; $CHARLEN = strlen($CHARS); $TOTALOPS = 1000; $STARTINGRECS = 10000; echo "\nMyISAM benchmark including deletes:\n"; for($t = 1; $t <= 56; $t += 5){ benchit($t, 'MyISAM', false); } echo "\nInnoDB benchmark including deletes:\n"; for($t = 1; $t <= 56; $t += 5){ benchit($t, 'InnoDB', false); } echo "\nMyISAM benchmark without deletes\n"; for($t = 1; $t <= 56; $t += 5){ benchit($t, 'MyISAM', true); } echo "\nInnoDB benchmark without deletes\n"; for($t = 1; $t <= 56; $t += 5){ benchit($t, 'InnoDB', true); } exit; function benchit($threads, $engine, $skipDeletes){ global $username; global $passwd; global $dbName; global $tableName; @unlink('bench.txt'); global $TOTALOPS; global $STARTINGRECS; if(! preg_match('/^(?:InnoDB|MyISAM)$/', $engine)){ die("Engine must be InnoDB or MyISAM\n"); } $mysqli = new mysqli('localhost', $username, $passwd, $dbName); $mysqli->query('drop table if exists ' . $tableName); if($mysqli->error){ die($mysqli->error); } $mysqli->query('create table ' . $tableName . ' (id int UNSIGNED NOT NULL PRIMARY KEY, count int UNSIGNED NOT NULL, mdm varchar(255) NOT NULL ) ENGINE=' . $engine . ' default charset=utf8'); if($mysqli->error){ die($mysqli->error); } for($i = 0; $i <= $STARTINGRECS; $i++){ $mysqli->query('insert into ' . $tableName . ' (id, count, mdm) values (' . $i . ', ' . $i . ', "' . makeString(255) . '")'); if($mysqli->error){ die($mysqli->error); } } unset($mysqli); $isChild = 0; $numChildren = $threads; for($i = 0; $i < $numChildren; $i++){ $pid = pcntl_fork(); if($pid){ //parent } else { //child $isChild = 1; //echo "Forked child\n"; break; } } if(! $isChild){ while($numChildren > 0){ pcntl_wait($status); $numChildren--; } $fh = fopen('bench.txt', 'r'); $tot = 0; $count = 0; while(! feof($fh)){ $t = trim(fgets($fh)); $tot += $t; $count++; } fclose($fh); echo "Threads: $threads\t\tEngine: $engine\t\tDelete op included: " . ($skipDeletes ? 'no' : 'yes') . "\t\tTime:\t" . sprintf('%.2f', $tot / $count) . "\n"; return; } else { //echo "Child starting inserts\n"; $mysqli = new mysqli('localhost', $username, $passwd, $dbName); $maxOps = round($TOTALOPS / $threads); $order = 'desc'; $start = microtime(true); for($i = 0; $i <= $maxOps; $i++){ $r = rand(1,99999999); $mysqli->query('insert IGNORE into ' . $tableName . ' (id, count, mdm) values (' . $r . ', ' . $r . ', "hello' . $r . '")'); if($mysqli->error){ die($mysqli->error); } $res = $mysqli->query('select * from ' . $tableName . ' where id=' . $r); if($mysqli->error){ die($mysqli->error); } if(! $skipDeletes){ $mysqli->query('delete from ' . $tableName . ' order by id ' . $order . ' limit 3'); if($mysqli->error){ die($mysqli->error); } if($order == 'desc'){ $order = 'asc'; } else { $order = 'desc'; } } } $t = sprintf('%.3f', (microtime(true) - $start)); writeTime($t); exit; } } function writeTime($t){ $fh = fopen('bench.txt', 'a'); flock($fh, LOCK_EX); fwrite($fh, $t . "\n"); flock($fh, LOCK_UN); fclose($fh); } function makeString($len){ global $CHARS; global $CHARLEN; $ret = ""; for($i = 0; $i < $len; $i++){ $ret .= substr($CHARS, mt_rand(0, $CHARLEN), 1); } return $ret; } ?>