Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <pre><?php
- $c = mysql_connect('localhost', 'root', '');
- if(!$c) die('!');
- echo mysql_select_db('test', $c)?'Connection':'Failure';
- echo PHP_EOL;
- echo ':::::::::::::::::::::::::BEGINNING NON-EXISTING TABLE::::::::::::::::::::::::::::::';
- $start = microtime(1);
- for( $i = 0; $i < 100000; $i++ )
- {
- mysql_query( 'SELECT 1 FROM foo' );
- }
- $end = microtime(1);
- echo ($end - $start) . " for bad select";
- echo PHP_EOL;
- $start = microtime(1);
- for( $i = 0; $i < 100000; $i++ )
- {
- $q = mysql_query("SELECT table_name FROM information_schema.tables WHERE table_schema = 'test' AND table_name = 'foo';");
- if( $q ) $r = mysql_num_rows($q);
- }
- $end = microtime(1);
- echo ($end - $start) . " for select from schema num rows";
- echo PHP_EOL;
- $start = microtime(1);
- for( $i = 0; $i < 100000; $i++ )
- {
- $q = mysql_query("SELECT table_name FROM information_schema.tables WHERE table_schema = 'test' AND table_name = 'foo';");
- if( $q ) $r = mysql_fetch_row($q);
- }
- $end = microtime(1);
- echo ($end - $start) . " for select from schema fetch row";
- echo PHP_EOL;
- $start = microtime(1);
- for( $i = 0; $i < 100000; $i++ )
- {
- $q = mysql_query("SHOW TABLES FROM test");
- while( $r = mysql_fetch_array($q) )
- {
- if($r['Tables_in_test'] == 'foo') break;
- }
- }
- $end = microtime(1);
- echo ($end - $start) . " for SHOW TABLES FROM test";
- echo PHP_EOL;
- echo ':::::::::::::::::::::::::BEGINNING EXISTING TABLE::::::::::::::::::::::::::::::';
- echo PHP_EOL;
- $start = microtime(1);
- for( $i = 0; $i < 100000; $i++ )
- {
- mysql_query( 'SELECT 1 FROM bar' );
- }
- $end = microtime(1);
- echo ($end - $start) . " for good select";
- echo PHP_EOL;
- $start = microtime(1);
- for( $i = 0; $i < 100000; $i++ )
- {
- $q = mysql_query("SELECT table_name FROM information_schema.tables WHERE table_schema = 'test' AND table_name = 'bar';");
- if( $q ) $r = mysql_num_rows($q);
- }
- $end = microtime(1);
- echo ($end - $start) . " for select from schema num rows";
- echo PHP_EOL;
- $start = microtime(1);
- for( $i = 0; $i < 100000; $i++ )
- {
- $q = mysql_query("SELECT table_name FROM information_schema.tables WHERE table_schema = 'test' AND table_name = 'bar';");
- if( $q ) $r = mysql_fetch_row($q);
- }
- $end = microtime(1);
- echo ($end - $start) . " for select from schema fetch row";
- echo PHP_EOL;
- $start = microtime(1);
- for( $i = 0; $i < 100000; $i++ )
- {
- $q = mysql_query("SHOW TABLES FROM test");
- while( $r = mysql_fetch_array($q) )
- {
- if($r['Tables_in_test'] == 'bar') break;
- }
- }
- $end = microtime(1);
- echo ($end - $start) . " for SHOW TABLES FROM test";
- echo PHP_EOL;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement