$db_server = "localhost";
$db_name = "test";
$db_user = "root";
$db_passwort = "";
//Ab hier nichts mehr ändern!
$db = mysql_connect($db_server,$db_user,$db_passwort) or die ("Konnte keine Verbindung zur Datenbank herstellen, bitte versuchen Sie es später erneut!");
$db_check = MYSQL_SELECT_DB($db_name);
//Tabelle erstellen
mysql_query(' CREATE TABLE `ip` (
`ip_int` INT NOT NULL ,
`ip_int_index` INT NOT NULL ,
`ip_varchar` VARCHAR( 15 ) NOT NULL ,
`ip_varchar_index` VARCHAR( 15 ) NOT NULL ,
`ip_text` TEXT NOT NULL ,
INDEX ( `ip_int_index` , `ip_varchar_index` )
) ENGINE = MYISAM ');
//Tabelle mit zufälligen IPs füllen
for ($x=1;$x<10000;$x++)
{
$ip=rand(150,244).'.'.rand(0,254).'.'.rand(0,254).'.'.rand(0,254);
mysql_query('insert into ip (ip_int,ip_int_index,ip_varchar,ip_varchar_index,ip_text) values ("'.ip2long($ip).'","'.ip2long($ip).'","'.$ip.'","'.$ip.'","'.$ip.'")');
}
echo 'DB mit 10.000 IPs gefüllt
';
flush();
//Zeit Messen: INT mit Index
$ip=rand(150,244).'.'.rand(0,254).'.'.rand(0,254).'.'.rand(0,254);
$t2=microtime(true);
for ($x=1;$x<500;$x++)
{
mysql_query('select * from ip where ip_int_index="'.(ip2long($ip)+$x).'" LIMIT 1');
}
$t2=microtime(true)-$t2;
echo 'INT (LONG) mit Index :'.$t2.' s
';
flush();
//Zeit Messen: INT ohne Index
$ip=rand(150,244).'.'.rand(0,254).'.'.rand(0,254).'.'.rand(0,254);
$t1=microtime(true);
for ($x=1;$x<500;$x++)
{
mysql_query('select * from ip where ip_int="'.(ip2long($ip)+$x).'" LIMIT 1');
}
$t1=microtime(true)-$t1;
echo 'INT (LONG) ohne Index :'.$t1.' s
';
flush();
//Zeit Messen: VarChar ohne Index
$ip=rand(150,244).'.'.rand(0,254).'.'.rand(0,254).'.'.rand(0,254);
$t3=microtime(true);
for ($x=1;$x<500;$x++)
{
mysql_query('select * from ip where ip_varchar="'.long2ip(ip2long($ip)+$x).'" LIMIT 1');
}
$t3=microtime(true)-$t3;
echo 'VarChar (15) ohne Index :'.$t3.' s
';
flush();
//Zeit Messen: VarChar mit Index
$ip=rand(150,244).'.'.rand(0,254).'.'.rand(0,254).'.'.rand(0,254);
$t4=microtime(true);
for ($x=1;$x<500;$x++)
{
mysql_query('select * from ip where ip_varchar_index="'.long2ip(ip2long($ip)+$x).'" LIMIT 1');
}
$t4=microtime(true)-$t4;
echo 'VarChar (15) mit Index :'.$t4.' s
';
flush();
//Zeit Messen: Text ohne Index
$ip=rand(150,244).'.'.rand(0,254).'.'.rand(0,254).'.'.rand(0,254);
$t5=microtime(true);
for ($x=1;$x<500;$x++)
{
mysql_query('select * from ip where ip_text="'.long2ip(ip2long($ip)+$x).'" LIMIT 1');
}
$t5=microtime(true)-$t5;
echo 'Text ohne Index :'.$t5.' s
';
flush();
mysql_query('DROP TABLE ip');
?>