  | 
			
			 
			|  
				
			 | 
			
			 
			| 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で実装しようとしすぎて周囲の反感を買いやすいのが最近の悩み。 
				 
				 
				  | 
				 
				 
			 | 
			
			 
			  
			 | 
			
			 
			|  
				
			 |