Then you'll find me in Madame Geneva

6 min read

Deviation Actions

xork's avatar
By
Published:
1.3K Views
keeping the demons at bay.
There's nothing like gin for drowning them in,
but they'll always be back on hanging day.


* * *


The following journal was payed for by The Committee for Testing Journal CSS Editor and the Cthulhu Society of Miskatonic University.


Hi, everybody! (Hi, Dr. Nick!). This journal update is all geekery, so civilians can turn back now. Anyone still left? Good, let's get started.





There was a side discussion in the Programming forum a while back about whether preincrement is more efficient than postincrement in PHP: i.e., is ++$i more efficient than $i++?


Well, I did some research -- using bcompiler (if you change #define BCOMPILER_DEBUG_ON 0 to #define BCOMPILER_DEBUG_ON 1 in bcompiler.c, it'll spit out interesting information to a file called bcompiler.log).


It turns out $i++ does use one more bytecode instruction than ++$i. I'm no good at Zend bytecode, but it looks like it's got to do with garbage collection (a FREE is generated for postincrement that isn't for preincrement); if you use the return value, it stays referenced, and post- and preincrement are the same (except for the obvious differences), but if you don't, the GC notices this and immediately kills the variable, thus generating the extra instruction. I think.


Just for fun and comparison, let's look at the following short C program:



int main(void)
{
    int i = 0, j = 0;

    j = i++;
    j = ++i;

    return 0;
}


The relevant parts of which compile into (using GCC 4.1.something, without optimisation, natch -- even a naked -O just strips out everything between { and }):



# "j = i++;":
movl -0xc(%ebp),%eax # copy "i" to accumulator
movl %eax,-0x8(%ebp) # copy accumulator to "j"
incl -0xc(%ebp)      # increment "i"

# "j = ++i;":
incl -0xc(%ebp)
movl -0xc(%ebp),%eax
movl %eax,-0x8(%ebp)


As you can see, it just moves the incl (increment long) depending on whether it should happen before or after the copy. I seem to recall reading not too long ago that the Java bytecode compiler does the same thing (but I don't know Java well enough to guarantee that it's guaranteed. It's not in C++, what with operator overloading and stuff (which is what C++ is in my head -- C plus stuff)).


What's my point with all this? I don't know, really. I just found it interesting.



* * *


If you, like I, use Splashy (it takes some pretty hackish config file editing to make it work on Slack 12, btw), you might like this Amiga-inspired theme. On boot, it displays the familiar hand-holding-a-disk image from Kickstart 1.3, and on error, it -- naturally -- shows a "Guru Meditation" (I didn't bother looking up which meditation it actually shows, I'll leave that as an exercise for the reader). I haven't submitted it to deviantART as it might possibly violate the rights of whoever holds the copyright to Kickstart 1.3. Though the way things are, whoever does hold the copyright probably doesn't even know they do.



* * *


Be seeing you.






Latest comic at "Valley of the Crescent Moon":
latest.png




© 2007 - 2024 xork
Comments0
Join the community to add your comment. Already a deviant? Log In