Facebook's HipHop Also a PHP Webserver
darthcamaro writes "As expected, Facebook today announced a new runtime for PHP, called HipHop. What wasn't expected were a few key revelations disclosed today by Facebook developer David Recordan. As it turns out, Facebook has been running HipHop for months and it now powers 90 percent of their servers — it's not a skunkworks project; it's a Live production technology. It's also not just a runtime, it's also a new webserver. 'In general, Apache is a great Web server, but when we were looking at how we get the next half percent or percent of performance, we didn't need all the features that Apache offers," Recordon said. He added, however, that he hopes an open source project will one day emerge around making HipHop work with Apache Web servers.'"
Hopefully he has upgraded to the "once in a while" switch replacement technique.
That struck me as weird, because as a programmer you usually start with conditionals and then move on to loops. I had a hard time believing that someone would know of "while(true)" and not "else if".
So I decided to run some tests over dinner. I'm no C++ programmer but here's how I went with this.
First I wrote a tests.cpp that looks like this:
#include
int main () {
int subType, mainType = 11;
Slashdot_Filter_Sucks // Editable section // End of editable
while (true) {
if (mainType == 7) {
subType = 4;
break;
}
if(mainType == 9) {
subType = 6;
break;
}
if(mainType == 11) {
subType = 9;
break;
}
break;
}
Slashdot_Filter_Sucks
std :: cout
I compiled that and it resulted in a 8120 bytes binary that ran in 0.005ms.
I thought about other obvious and simple ways to write this code and I created four more versions that are identical except for the code between the dividers (I had pretty asterisk lines but Slashdot's junk filter made me take it off). They are:
testif.cpp (test using an if/else statement):
if (mainType == 7) subType = 4;
else if (mainType == 9) subType = 6;
else if (mainType == 11) subType = 9;
testifonly.cpp (no else, only ifs):
if (mainType == 7) subType = 4;
if (mainType == 9) subType = 6;
if (mainType == 11) subType = 9;
testswitch.cpp (using a switch statement):
switch(mainType) {
case 7: subType = 4;
case 9: subType = 6;
case 11: subType = 9;
}
testp.cpp (subtract 3 from mainType since that seemed like a pattern):
subType = mainType - 3;
I compiled everything using g++ then I ran time ./output. All the versions ran on average in 0.005ms, however, the binary sizes were different:
#ls -l (ordered by size)
8072 testp
8109 testifonly
8120 tests
8121 testif
8125 testswitch
Ok, no case here in terms of size. So I tried compiling again with -O3, and the results were:
#ls -l (ordered by size)
8024 testp_o3
8024 tests_o3
8025 testif_o3
8029 testifonly_o3
8029 testswitch_o3
Here it seems that the subtraction and the weird while/break method have the smallest file size. Without code context, one can imagine that subType was to be left alone if mainType was not 7,9 or 11. Which would mean the subtraction code wouldn't work in that scenario.
Now, I don't know the intricacies of C++ or Assembly, but I have to wonder if this was the work of a moron or someone who knew exactly what they were doing and did so for a reason.
Again, without context, none of this matters.
If you can't mod them join them.