home *** CD-ROM | disk | FTP | other *** search
/ Enter 2004 June / ENTER.ISO / files / xampp-win32-1.4.5-installer.exe / xampp / benchmark_drivers.php < prev    next >
Encoding:
PHP Script  |  2004-03-24  |  5.3 KB  |  136 lines

  1. <?php
  2. /* vim: set expandtab tabstop=4 shiftwidth=4: */
  3. // +----------------------------------------------------------------------+
  4. // | Copyright (c) 2002 Brent Cook                                        |
  5. // +----------------------------------------------------------------------+
  6. // | This library is free software; you can redistribute it and/or        |
  7. // | modify it under the terms of the GNU Lesser General Public           |
  8. // | License as published by the Free Software Foundation; either         |
  9. // | version 2.1 of the License, or (at your option) any later version.   |
  10. // |                                                                      |
  11. // | This library is distributed in the hope that it will be useful,      |
  12. // | but WITHOUT ANY WARRANTY; without even the implied warranty of       |
  13. // | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU    |
  14. // | Lesser General Public License for more details.                      |
  15. // |                                                                      |
  16. // | You should have received a copy of the GNU Lesser General Public     |
  17. // | License along with this library; if not, write to the Free Software  |
  18. // | Foundation, Inc., 59 Temple Place, Suite 330,Boston,MA 02111-1307 USA|
  19. // +----------------------------------------------------------------------+
  20. // | Author: Brent Cook <busterb@mail.utexas.edu>                         |
  21. // +----------------------------------------------------------------------+
  22. //
  23. // $Id: benchmark_drivers.php,v 1.6 2002/09/25 17:37:49 busterb Exp $
  24. //
  25.  
  26. ini_set('include_path',ini_get('include_path').':../../');
  27. require_once 'DBA.php';
  28. require_once 'PEAR.php';
  29.  
  30. $testDataArray = array ('11111111111111111111',
  31.                         '222222222222222222222222',
  32.                         '3333333333333333333333333333',
  33.                         '44444444444444444444444444444444',
  34.                         '555555555555555555555555555555555555',
  35.                         '6666666666666666666666666666666666666666',
  36.                         '77777777777777777777777777777777777777777777',
  37.                         '888888888888888888888888888888888888888888888888',
  38.                         '9999999999999999999999999999999999999999999999999999');
  39.  
  40. $maxDataIndex = sizeof ($testDataArray)-1;
  41.  
  42. $maxTestKeys = array(1600, 3200, 6400, 12800, 25600);
  43.  
  44. $transactionsInterval = 2000;
  45.  
  46. $maxTransactions = $transactionsInterval * 8;
  47.  
  48. $prefix = './';
  49.  
  50. function getmicrotime(){ 
  51.     list($usec, $sec) = explode(" ",microtime()); 
  52.     return((float)$usec + (float)$sec); 
  53.  
  54. foreach (DBA::getDriverList() as $driver) {
  55.     echo "Benchmarking driver: $driver\n";
  56.     $testDB = DBA::create($driver);
  57.  
  58.     foreach ($maxTestKeys as $maxTestKey) {
  59.  
  60.         $dat_fp = fopen($prefix."{$driver}_{$maxTestKey}.dat", 'w');
  61.         for ($transactions=$transactionsInterval;
  62.             $transactions <= $maxTransactions;
  63.             $transactions+=$transactionsInterval) {
  64.  
  65.             $result = $testDB->open($prefix.'benchmark_db_'.$driver, 'n');
  66.             if (PEAR::isError($result)) {
  67.                 echo $result->getMessage()."\n";
  68.             } else {
  69.                 // only measure successful transactions
  70.                 $actualTransactions = 0;
  71.  
  72.                 // begin stopwatch
  73.                 $start = getmicrotime();
  74.  
  75.                 for ($i=0; $i<$transactions; ++$i) {
  76.                     $testKey = rand (0, $maxTestKey);
  77.                     $testData = $testDataArray[rand(0, $maxDataIndex)];
  78.                     switch (rand(0, 3)) {
  79.                         case 0:
  80.                             if (!$testDB->exists($testKey)) {
  81.                                 ++$actualTransactions;
  82.                                 $testDB->insert($testKey, $testData);
  83.                             }
  84.                             break;
  85.                         case 1:
  86.                             if ($testDB->exists($testKey)) {
  87.                                 ++$actualTransactions;
  88.                                 $testDB->remove($testKey);
  89.                             }
  90.                             break;
  91.                         case 2:
  92.                             $testDB->replace($testKey, $testData);
  93.                             break;
  94.                         case 3:
  95.                             if ($testDB->exists($testKey)) {
  96.                                 ++$actualTransactions;
  97.                                 $testDB->fetch($testKey);
  98.                             }
  99.                     }
  100.                 }
  101.                 $testDB->close();
  102.             }
  103.  
  104.             // end stopwatch
  105.             $stop = getmicrotime();
  106.             $line = $actualTransactions.' '.($stop - $start)."\n";
  107.             echo "Keys: $maxTestKey Transactions: $line";
  108.             fwrite($dat_fp, $line);
  109.         }
  110.         fclose($dat_fp);
  111.     }
  112.  
  113.     // make a gnuplot data file
  114.     $graph_data = <<<EOT
  115. set size 1.0, 1.0
  116. set terminal postscript portrait "Helvetica" 12
  117. set title "driver: $driver"
  118. set xlabel "# of transactions"
  119. set ylabel "time in seconds"
  120. set out "$driver.ps"
  121. plot
  122. EOT;
  123.  
  124.     foreach ($maxTestKeys as $maxTestKey) {
  125.         $graph_data .= " \"{$driver}_{$maxTestKey}.dat\" using 1:2 title '".
  126.                     "$driver, $maxTestKey keys' with lines,\\\n";
  127.     }
  128.  
  129.     // write the gnuplot data file, trimming off that last comma :P
  130.     $graph_fp = fopen($prefix.$driver.'_graph', 'w');
  131.     fwrite($graph_fp, substr($graph_data, 0, -3));
  132.     fclose($graph_fp);
  133. }
  134. ?>
  135.