home *** CD-ROM | disk | FTP | other *** search
/ Chip 2001 January / Chip_2001-01_cd1.bin / tema / mysql / mysql-3.23.28g-win.exe / DATA1.CAB / Benchmark_Files / bench / test-big-tables < prev    next >
Text File  |  2000-11-22  |  4KB  |  155 lines

  1. #!/my/gnu/bin/perl5
  2. # Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB
  3. #
  4. # This library is free software; you can redistribute it and/or
  5. # modify it under the terms of the GNU Library General Public
  6. # License as published by the Free Software Foundation; either
  7. # version 2 of the License, or (at your option) any later version.
  8. #
  9. # This library is distributed in the hope that it will be useful,
  10. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  12. # Library General Public License for more details.
  13. #
  14. # You should have received a copy of the GNU Library General Public
  15. # License along with this library; if not, write to the Free
  16. # Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
  17. # MA 02111-1307, USA
  18. #
  19. # Test of extreme tables.
  20. #
  21.  
  22. ##################### Standard benchmark inits ##############################
  23.  
  24. use DBI;
  25. use Benchmark;
  26.  
  27. $opt_loop_count=1000; # Change this to make test harder/easier
  28. $opt_field_count=1000;
  29.  
  30. chomp($pwd = `pwd`); $pwd = "." if ($pwd eq '');
  31. require "$pwd/bench-init.pl" || die "Can't read Configuration file: $!\n";
  32.  
  33. $opt_field_count=min($opt_field_count,$limits->{'max_columns'},
  34.              ($limits->{'query_size'}-30)/14);
  35.  
  36. $opt_loop_count*=10 if ($opt_field_count<100);    # mSQL has so few fields...
  37.  
  38. if ($opt_small_test)
  39. {
  40.   $opt_loop_count/=10;
  41.   $opt_field_count/=10;
  42. }
  43.  
  44.  
  45. print "Testing of some unusual tables\n";
  46. print "All tests are done $opt_loop_count times with $opt_field_count fields\n\n";
  47.  
  48.  
  49. ####
  50. ####  Testing many fields
  51. ####
  52.  
  53. $dbh = $server->connect();
  54. print "Testing table with $opt_field_count fields\n";
  55.  
  56. $sth = $dbh->do("drop table bench1");
  57.  
  58. my @fields=();
  59. my @index=();
  60. my $fields="i1";
  61. push(@fields,"$fields int");
  62. $values= "1," x ($opt_field_count-1) . "1";
  63. for ($i=2 ; $i <= $opt_field_count ; $i++)
  64. {
  65.   push(@fields,"i${i} int");
  66.   $fields.=",i${i}";
  67. }
  68.  
  69. $start_time=new Benchmark;
  70.  
  71. do_many($dbh,$server->create("bench1",\@fields,\@index));
  72. $sth = $dbh->do("insert into bench1 values ($values)") or die $DBI::errstr;
  73.  
  74. if ($opt_fast && defined($server->{vacuum}))
  75. {
  76.   $server->vacuum(0,\$dbh);
  77. }
  78.  
  79. test_query("Testing select * from table with 1 record",
  80.        "Time to select_many_fields",
  81.        "select * from bench1",
  82.        $dbh,$opt_loop_count);
  83.  
  84. test_query("Testing select all_fields from table with 1 record",
  85.        "Time to select_many_fields",
  86.        "select $fields from bench1",
  87.        $dbh,$opt_loop_count);
  88.  
  89. test_query("Testing insert VALUES()",
  90.        "Time to insert_many_fields",
  91.        "insert into bench1 values($values)",
  92.        $dbh,$opt_loop_count);
  93.  
  94. if ($opt_fast && defined($server->{vacuum}))
  95. {
  96.   $server->vacuum(0,\$dbh);
  97. }
  98.  
  99. test_command("Testing insert (all_fields) VALUES()",
  100.          "Time to insert_many_fields",
  101.          "insert into bench1 ($fields) values($values)",
  102.          $dbh,$opt_loop_count);
  103.  
  104. $sth = $dbh->do("drop table bench1") or die $DBI::errstr;
  105.  
  106. if ($opt_fast && defined($server->{vacuum}))
  107. {
  108.   $server->vacuum(0,\$dbh);
  109. }
  110.  
  111. ################################ END ###################################
  112. ####
  113. #### End of the test...Finally print time used to execute the
  114. #### whole test.
  115.  
  116. $dbh->disconnect;
  117.  
  118. end_benchmark($start_time);
  119.  
  120.  
  121. ############################ HELP FUNCTIONS ##############################
  122.  
  123. sub test_query
  124. {
  125.   my($test_text,$result_text,$query,$dbh,$count)=@_;
  126.   my($i,$loop_time,$end_time);
  127.  
  128.   print $test_text . "\n";
  129.   $loop_time=new Benchmark;
  130.   for ($i=0 ; $i < $count ; $i++)
  131.   {
  132.     defined(fetch_all_rows($dbh,$query)) or die $DBI::errstr;
  133.   }
  134.   $end_time=new Benchmark;
  135.   print $result_text . "($count): " .
  136.   timestr(timediff($end_time, $loop_time),"all") . "\n\n";
  137. }
  138.  
  139.  
  140. sub test_command
  141. {
  142.   my($test_text,$result_text,$query,$dbh,$count)=@_;
  143.   my($i,$loop_time,$end_time);
  144.  
  145.   print $test_text . "\n";
  146.   $loop_time=new Benchmark;
  147.   for ($i=0 ; $i < $count ; $i++)
  148.   {
  149.     $dbh->do($query) or die $DBI::errstr;
  150.   }
  151.   $end_time=new Benchmark;
  152.   print $result_text . "($count): " .
  153.   timestr(timediff($end_time, $loop_time),"all") . "\n\n";
  154. }
  155.