note 77107 added to function.mysqli-prepare

From: Date: Wed, 15 Aug 2007 17:39:49 +0000
Subject: note 77107 added to function.mysqli-prepare
Groups: php.notes 
Request: Send a blank email to php-notes+get-129500@lists.php.net to get a copy of this message
Performance note to those who wonder. I performed a test where first of all inserted about 30,000 posts with one PK:id and a varchar(20), where the varchar data was md5-hash for the current iterator value just to fill with some data. The test was performed on a dedicated ubuntu 7.04 server with apache2/php5/mysql2.9 running on Athlon 64 - 3000+ with 512MB of RAM. The queries where tested with a for-loop from 0 to 30000 first with: <?php for ( $i = 0; $i <= 30000; ++$i ) { $result = $mysqli->query("SELECT * FROM test WHERE id = $i"); $row = $result->fetch_row(); echo $row[0]; //prints id } ?> which gave a page-load time of about 3.3seconds avarage, then with this loop: <?php $stmt = $mysqli->prepare("SELECT * FROM test WHERE id = ?"); for ( $i = 0; $i <= 30000; ++$i ) { $stmt->bind_param("i", $i); $stmt->execute(); $stmt->bind_result($id, $md5); $stmt->fetch(); echo $id; } $stmt->close(); ?> and the avarage page-load was lowered by 1.3sec, which means about 2.0 sec avarage! Guess the performance difference could be even greater on a more complex/larger table and more complex SQL-queries. ---- Server IP: 212.63.193.10 Probable Submitter: 85.227.234.167 ---- Manual Page -- http://www.php.net/manual/en/function.mysqli-prepare.php Edit -- https://master.php.net/note/edit/77107 Del: integrated -- https://master.php.net/note/delete/77107/integrated Del: useless -- https://master.php.net/note/delete/77107/useless Del: bad code -- https://master.php.net/note/delete/77107/bad+code Del: spam -- https://master.php.net/note/delete/77107/spam Del: non-english -- https://master.php.net/note/delete/77107/non-english Del: in docs -- https://master.php.net/note/delete/77107/in+docs Del: other reasons-- https://master.php.net/note/delete/77107 Reject -- https://master.php.net/note/reject/77107 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#129500) next »