Re: Which is quicker, if-else statements

From: Date: Wed, 19 Mar 2003 03:38:12 +0000
Subject: Re: Which is quicker, if-else statements
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-140240@lists.php.net to get a copy of this message
On Wed, 19 Mar 2003 00:39:11 +0100, Ernest E Vogelsinger wrote about "Re: [PHP] Which is quicker, if-else statements" what the universal translator turned into this: >Noticeable? Probably not, except you're timing loops of a million or more >cycles... but it's clear that the second method needs more time (in terms >of cpu cycles) than the first one. > >In Intel speak, what would a compiler translate these code examples to? > >if (a == b) {} else {} > mov eax, {a} > cmp eax, {b} > jnz L01 >; the "true" block goes here > jmp L02 >L01: >; the "false" (else) block goes here >L02: > >As you can see there's two memory operations and one comparison. I'm totally lost here ... what does that mean??? Reminds me of assembler, except that assembler is more like: 0001 jnp e002 e003 0005 0002 jmp e002 e003 0008 And so on (not sure if that's fully correct ... haven't touched assembler since '92) ... Please ellaborate Ernest ... >However, PHP is _not_ a compiler, it's an interpreter. It "compiles" code >at runtime and has not the ability to perform exhaustive optimizations >which would cost far more time than can be gained within a single >execution. Additionally there's the time needed to parse the input stream >(tokenize, add to symbol table, execute token and expression parser, etc >etc). With interpreting languages the differences will rocket skyhigh >compared to compiled executables. Doesn't PHP precompile the files and shove the result into the cache? Or did I get that wrong ??? Rene -- Rene Brehmer This message was written on 100% recycled spam. Come see! My brand new site is now online! http://www.metalbunny.net

« previous php.general (#140240) next »