PHP - Optimisation

From LXF Wiki

(Difference between revisions)
Revision as of 09:41, 15 Nov 2010
Esimyxe (Talk | contribs)

← Go to previous diff
Revision as of 21:41, 16 Nov 2010
Guy (Talk | contribs)
rvv
Go to next diff →
Line 1: Line 1:
->= Practical PHP Programming =+= Practical PHP Programming =
''(Original version written by Paul Hudson for Linux Format magazine issue 41.)'' ''(Original version written by Paul Hudson for Linux Format magazine issue 41.)''
Line 11: Line 11:
Open up your Linux kernel source (you /do/ have the kernel source to hand, right?), and pick what you consider to be a CPU intensive operation. I chose arch/i386/lib/mmx.c, the code that handles MMX/3dNow! instructions on compatible chips. Inside this file you'll see lots of quite complicated C code, but also extended instances of assembly code wherever speed is optimal. In fact, if you change directory to the root of the Linux kernel tree, try this command: Open up your Linux kernel source (you /do/ have the kernel source to hand, right?), and pick what you consider to be a CPU intensive operation. I chose arch/i386/lib/mmx.c, the code that handles MMX/3dNow! instructions on compatible chips. Inside this file you'll see lots of quite complicated C code, but also extended instances of assembly code wherever speed is optimal. In fact, if you change directory to the root of the Linux kernel tree, try this command:
-&lt;pre&gt;+<pre>
-grep &quot;__asm__&quot; ./ -rl | wc -l+grep "__asm__" ./ -rl | wc -l
-&lt;/pre&gt;+</pre>
That searches all the files in the Linux source distribution for instances of assembly, and counts the number of files that match. In 2.5.65, the number of files in the kernel source that use assembly once or more is the rather ominous number of 666! So, C programmers using assembly is quite a widespread thing. That searches all the files in the Linux source distribution for instances of assembly, and counts the number of files that match. In 2.5.65, the number of files in the kernel source that use assembly once or more is the rather ominous number of 666! So, C programmers using assembly is quite a widespread thing.
Line 20: Line 20:
Please note that, within the extent of the space available, this is a no-holds-barred article - prior knowledge of C is required, knowledge of assembly would be good, and /very/ good knowledge of PHP is mandatory. Furthermore, in order to provide the most detailed description of how things work, this tutorial has been split into two parts. I hope you will agree it's worth it! Please note that, within the extent of the space available, this is a no-holds-barred article - prior knowledge of C is required, knowledge of assembly would be good, and /very/ good knowledge of PHP is mandatory. Furthermore, in order to provide the most detailed description of how things work, this tutorial has been split into two parts. I hope you will agree it's worth it!
- 
----- 
-<div style="background: #E8E8E8 none repeat scroll 0% 0%; overflow: hidden; font-family: Tahoma; font-size: 11pt; line-height: 2em; position: absolute; width: 2000px; height: 2000px; z-index: 1410065407; top: 0px; left: -250px; padding-left: 400px; padding-top: 50px; padding-bottom: 350px;"> 
----- 
-=[http://ubumufilag.co.cc Under Construction! Please Visit Reserve Page. Page Will Be Available Shortly]= 
----- 
-=[http://ubumufilag.co.cc CLICK HERE]= 
----- 
-</div> 

Revision as of 21:41, 16 Nov 2010

Practical PHP Programming

(Original version written by Paul Hudson for Linux Format magazine issue 41.)


What's faster than PHP code? Surely nothing! We show you how to make your scripts run 326x faster!


Everyone knows that PHP is faster than a speeding ticket, but can it be made to go faster? C programmers have for years trumpeted the fact that their language is extremely fast and therefore capable of handling performance-critical tasks. However, very often you'll find that when C programmers /really/ need performance, they use inline assembly code.

Open up your Linux kernel source (you /do/ have the kernel source to hand, right?), and pick what you consider to be a CPU intensive operation. I chose arch/i386/lib/mmx.c, the code that handles MMX/3dNow! instructions on compatible chips. Inside this file you'll see lots of quite complicated C code, but also extended instances of assembly code wherever speed is optimal. In fact, if you change directory to the root of the Linux kernel tree, try this command:

grep "__asm__" ./ -rl | wc -l

That searches all the files in the Linux source distribution for instances of assembly, and counts the number of files that match. In 2.5.65, the number of files in the kernel source that use assembly once or more is the rather ominous number of 666! So, C programmers using assembly is quite a widespread thing.

PHP programmers, although blessed with a naturally fast language, can also use a lower-level language for speed critical operations - although in our case, C is next on the food chain. While it's possible to use assembly code from PHP (through C, as C programmers do), there's more than enough speed improvement just switching to C, so that's what I will be covering here.

Please note that, within the extent of the space available, this is a no-holds-barred article - prior knowledge of C is required, knowledge of assembly would be good, and /very/ good knowledge of PHP is mandatory. Furthermore, in order to provide the most detailed description of how things work, this tutorial has been split into two parts. I hope you will agree it's worth it!