我们要做个程序在LAN使用,客户说经常会一次插入大量的数据,所以要求效率。现在localhost测试都是这样的效率
领导说如果实在效率太慢还是考虑使用cgi来做。

解决方案 »

  1.   

    让领导多批些银子下来买硬件吧
    我在我电脑上试
    插入10000条数据为2.45秒 更新1万条数据为0.20秒
    插入10万数据为22.2秒p2.4 256mb 测试数据
    代码
    <?php
    class Ctime{
      var $starttime;
       function Ctime()
       {
      $mtime=microtime();
      $mtime=explode(' ',$mtime);
      $mtime=$mtime[1]+$mtime[0];
      $this->starttime=$mtime;
        }
      function endTimer()
      {
      $mtime=microtime();
      $mtime=explode(' ',$mtime);
      $endtime=$mtime[1]+$mtime[0];
      $endtime=round(($endtime-$this->starttime),4);
      return $endtime;
      }
    }
    $ctime=new CTime();
    $dsn="mysql:dbname=com;host=127.0.0.1";
    $username="root";
    $userpass="123456";try {
       $dbh = new PDO($dsn, $username, $userpass);
    } catch (PDOException $e) {
       echo 'Connection failed: ' . $e->getMessage();
    }
    $sql="INSERT INTO `com_gb_topic` ( `id` , `subject` , `content` , `date` , `poster` , `email` , `msn` , `url` , `qq` , `avatar` , `ip` , `reply` , `reply_time` ) VALUES ('', 'wwwwwwwwwwwwww', 'aaaaaaaaaaaaaa', '0000-00-00 00:00:00', '', '', '', '', '', '', '', '', '0000-00-00 00:00:00')";
    //$sql="UPDATE `com_gb_topic` SET `subject` = 'pppppppppp',`content` = 'cccccccccccc';";
    for($i=0;$i<100000;$i++)
    {
      $dbh->exec($sql);
    }
    echo $ctime->endTimer();
    ?>
      

  2.   

    如果为更新时候记得把for注释掉