Part2:トライ!SQLite(2) (1/2)

まるごと PHP!
まるごと PHP!

Part2:トライ!SQLite(2)

著者:桝形誠二(MASUGATA, Seiji)   2005/3/7
1   2  次のページ
性能評価(1)

  今度は、前回作成したテーブルhogeとhuga を使って、SQLiteの性能評価をしてみることにしましょう。MySQL(ここではMyISAM型を利用)とSQLiteでは、同じ条件で、どのくらい性能差があるのかを検証します。次の5つのシナリオに基づいて実行します。
  • シナリオ1:INSERT処理を10万件分行う(リスト1、リスト2)

リスト1:insert.php
<?
$Connect = sqlite_open( "testdb" ) or die( "db open error!!" );
sqlite_query( $Connect, "begin" );
for( $XX = 1; $XX < 100001; ++$XX )
{
$Int = sprintf( "%07d", $XX );
$String = "TEST".$Int;
sqlite_query( $Connect, "insert into hoge values ( ".$XX.", '".$String."' )" );
}
sqlite_query( $Connect, "commit" );

sqlite_close( $Connect );

?>

リスト2:insert_m.php
<?
$Connect = mysql_connect( "localhost", "root", "" ) or die ( "connect error!!" );

mysql_select_db( "testdb", $Connect );

for( $XX = 1; $XX < 100001; ++$XX )
{
$Int = sprintf( "%07d", $XX );
$String = "TEST".$Int;

mysql_query( "insert into hoge values ( ".$XX.", '".$String."' )", $Connect );
}

mysql_close( $Connect );
?>
  • シナリオ2:UPDATE処理を10万件分行う(リスト3、リスト4)

リスト3:update.php
<?
$Connect = sqlite_open( "testdb" ) or die( "db open error!!" );

sqlite_query( $Connect, "begin" );

for( $XX = 1; $XX < 100001; ++$XX )
{
$Int = sprintf( "%07d", $XX );
$String = $Int."TEST";

sqlite_query( "update hoge set bar = '".$String."' where foo = ".$XX, $Connect );
}

sqlite_query( $Connect, "commit" );

sqlite_close( $Connect );

?>

リスト4:update_m.php
<?
$Connect = mysql_connect ( "localhost", "root", "" ) or die( "connect error!!" );

mysql_select_db ( "testdb", $Connect );

for( $XX = 1; $XX < 100001; ++$XX )
{
$Int = sprintf( "%07d", $XX );
$String = $Int."TEST";

mysql_query( "update hoge set bar = '".$String."' where foo = ".$XX, $Connect );
}

mysql_close( $Connect );

?>
  • シナリオ3:SELECT処理(10万件すべてを取得)を行う(リスト5、リスト6)

リスト5:select.php
<?
$Connect = sqlite_open( "testdb" ) or die( "db open error!!" );

sqlite_query( $Connect, "begin" );

$Result = sqlite_query( $Connect, "select foo, bar from hoge order by foo" );
while( $Array = sqlite_fetch_array ( $Result ) )

{
print_r( $Array );
}

sqlite_query( $Connect, "commit" );

sqlite_close( $Connect );

?>

リスト6:select_m.php
<?
$Connect = mysql_connect ( "localhost", "root", "" ) or die( "connect error!!" );

mysql_select_db( "testdb", $Connect );

$Result = mysql_query( "select foo, bar from hoge order by foo", $Connect );

while( $Array = mysql_fetch_array ( $Result ) )
{
print_r( $Array );
}

mysql_close( $Connect );

?>
1   2  次のページ



著者プロフィール
桝形 誠二
様々な言語を経験していく中でPHPと出会い、初心者に易しいという魅力に惹かれ続けて早5年。色んな事をPHPで実装しようとしすぎて周囲の反感を買いやすいのが最近の悩み。


INDEX
Part2:トライ!SQLite(2)
性能評価(1)
  性能評価(2)
まるごと PHP!
Part1 PHP5のオブジェクト指向(1)
PHP5のオブジェクト指向(2)
PHP5のオブジェクト指向(3)
Part2 トライ!SQLite(1)
トライ!SQLite(2)
トライ!SQLite(3)
Part3 MySQL拡張サポート(1)
MySQL拡張サポート(2)
MySQL拡張サポート(3)
Part4 PDO(PHP Data Object)データベース抽象化レイヤクラス(1)
PDO(PHP Data Object)データベース抽象化レイヤクラス(2)
PDO(PHP Data Object)データベース抽象化レイヤクラス(3)
Part5 PHP5のXMLサポート(1)
PHP5のXMLサポート(2)
PHP5のXMLサポート(3)
Part6 PHP4からPHP5への移行のポイント

人気記事トップ10

人気記事ランキングをもっと見る