9.6.4 Impeared performance?This is NOT the latest copy of this book; click here for the latest version.
Bad puns aside, it is a legitimate concern if you are wondering at what cost the power of PEAR::DB comes. When you use direct database function calls, such as mysql_query(), there is no need to jump through hoops to figure out what database type is being referenced or the like, because the call is unambiguous. In PEAR::DB, a lot of extra work has to be done behind the scenes to make it work smoothly across the different DBMSs, and this has quite a heavy speed toll.
On average, you are likely to find PEAR::DB code will run at about 3/8 the speed of the equivalent DBMS-specific code (that is, just less than half the speed), although this will of course vary depending on the types of query you do. It is of course impossible for PEAR::DB to ever run as fast as native DBMS calls because PEAR::DB is written using PHP, and PHP scripts are much slower than compiled C programs.
However, you need to weigh the performance hit against the extra flexibility offered by PEAR::DB. PEAR::DB code can be transferred from MySQL to PostgreSQL to Microsoft SQL Server to Oracle, all simply by changing the initial DSN used to connect to the server. Furthermore, functionality such as prepared statements bring the database code closer to that of Microsoft's ADO technology, and should therefore help entice ASP and ASP.NET programmers over to PHP.
|
Want to see this stuff in print? PHP in a Nutshell takes the core topics covered here, adds in thousands of edits from the editorial team and myself, and combines them to make an unbeatable reference for PHP programmers at all levels.
My latest book has hundreds more tips on how to use PHP, Apache, and MySQL, plus Perl, Python, shell scripts, performance tuning, and more!
|