|
|
前のページ 1 2
|
|
性能評価(2) |
|
- シナリオ4:DELETE処理を10万件分行う(リスト7、リスト8)
|
リスト7:delete.php
|
<?
$Connect = sqlite_open( "testdb" ) or die( "db open error!!" );
sqlite_query( $Connect, "begin" );
for( $XX = 1; $XX < 100001; ++$XX )
{
sqlite_query( $Connect, "delete from hoge where foo = ".$XX );
}
sqlite_query( $Connect, "commit" );
sqlite_close( $Connect );
?>
|
リスト8:delete_m.php
|
<?
$Connect = mysql_connect ( "localhost", "root", "" ) or die( "connect error!!"
);
mysql_select_db( "testdb", $Connect );
for( $XX = 1; $XX < 100001; ++$XX )
{
mysql_query( "delete from hoge where foo = ".$XX, $Connect );
}
mysql_close( $Connect );
?>
|
|
- シナリオ5:ランダム。SELECT/UPDATE/INSERT/DELETEを交互に繰り返す(リスト9、リスト10)
|
リスト9:rand.php
|
<?
$Connect = sqlite_open( "testdb" ) or die( "db open error!!" );
sqlite_query( $Connect, "begin" );
mt_srand( (double)microtime( ) * 1000000 );
for( $XX = 1; $XX < 100001; ++$XX )
{
$Ransu = sprintf( "%d", mt_rand ( 0, 9 ) );
if( $Ransu == 2 )
{
$Int = sprintf( "%07d", $XX );
$String = "テスト".$Int;
sqlite_query( $Connect, "insert into hoge values( ".$XX.", '".$String."' )" );
}
else
if( $Ransu == 5 )
{
sqlite_query( $Connect, "delete from hoge where foo = ".$XX );
}
else
if( $Ransu == 7 )
{
$Int = sprintf( "%07d", $XX );
$String = $Int."TEST";
sqlite_query( $Connect, "update hoge set bar = '".$String."' where foo = ".$XX );
}
else
{
$Result = sqlite_query( $Connect, "select foo, bar from hoge where foo = ".$XX );
while( $Array = sqlite_fetch_array ( $Result ) )
{
print_r( $Array );
}
}
}
sqlite_query( $Connect, "commit" );
sqlite_close( $Connect );
?>
|
リスト10:rand_m.php
|
<?
$Connect = mysql_connect( "localhost", "root", "" ) or die( "connect error!!" );
mysql_select_db( "testdb", $Connect );
mt_srand( (double)microtime( ) * 1000000 );
for( $XX = 1; $XX < 100001; ++$XX )
{
$Ransu = sprintf( "%d", mt_rand( 0, 9 ) );
if( $Ransu == 2 )
{
$Int = sprintf( "%07d", $XX );
$String = "TEST".$Int;
mysql_query( "insert into hoge values ( ".$XX.", '".$String."' )", $Connect );
}
else
if( $Ransu == 5 )
{
mysql_query( "delete from hoge where foo = ".$XX, $Connect );
}
else
if( $Ransu == 7 )
{
$Int = sprintf( "%07d", $XX );
$String = $Int."TEST";
mysql_query( "update hoge set bar = '".$String."' where foo = ".$XX, $Connect );
}
else
{
$Result = mysql_query( "select foo, bar from hoge where foo = ".$XX, $Connect );
while( $Array = mysql_fetch_array ( $Result ) )
{
print_r( $Array );
}
}
}
mysql_close( $Connect );
?>
|
結果は図5のようになりました(realは総処理時間、userはユーザーCPU時間、sysはシステムCPU時間)。
|
図5:SQLiteとMySQLの性能評価
|
驚くべきことに、SQLiteはMySQL(MyISAM)と比較して遜色ない結果でした。しかし、いくつか気になった点を報告しておきましょう。
この検証を行っている際に気付いたのですが、SQLiteは同時実行性に欠けるようです。実際、性能テストの最中にコマンドラインから直接アクセスすると、排他制御エラーが発生しました。また、トランザクション処理を行わない場合、大幅な遅延が発生して使いものになりませんでした。
性能テストは通常利用されるケースを想定していないので少々強引な結論かもしれませんが、実際に利用する場合には注意したほうがよいでしょう。ただ、Webアプリケーションの場合、大きなトランザクションブロックで処理することはそう多くないはずなので、あまり気にすることはないのかもしれません。
|
前のページ 1 2
|
|
|
|
著者プロフィール
桝形 誠二
様々な言語を経験していく中でPHPと出会い、初心者に易しいという魅力に惹かれ続けて早5年。色んな事をPHPで実装しようとしすぎて周囲の反感を買いやすいのが最近の悩み。
|
|
|
|
|
|
|