#!/usr/bin/perl
use DBI;
use Benchmark ":hireswallclock";

$opt_loop_count=100000;		# number of loops(rows)
$max_tables=50000;

$db_host="localhost";
$db_socket="/tmp/mysql.sock";
$db_name="test";
$db_engine="MyISAM";
$db_stat=1;                     # set to 1 to get handler stats
                                # before and after update_with_key_prefix operation

$dbh = DBI->connect("dbi:mysql:$db_name;host=$db_host;mysql_socket=$db_socket","root","") or die $DBI::errstr;

####
#### Create needed table
####



for ($i=1 ; $i <= $max_tables ; $i++)
{
  $dbh->do("drop table if exists bench_$i");
}

$loop_time=new Benchmark;

print "Testing create of tables\n";

for ($i=1 ; $i <= $max_tables ; $i++)
{
  if (!$dbh->do("create table bench_$i (i int NOT NULL,
                                       d double,
                                       f float,
                                       s char(10),
                                       v varchar(100),
                                       primary key (i)
                                      )"))

  {
    print $DBI::errstr,"\n";
    # Got an error; Do cleanup
    for ($i=1 ; $i <= $max_tables ; $i++)
    {
      $dbh->do("drop table if exists bench_$i");
    }
    die "Test aborted";
  }
}

$end_time=new Benchmark;
print "Time for create_MANY_tables ($max_tables): ".
  timestr(timediff($end_time, $loop_time),"all") . "\n\n";

$dbh->disconnect();
