This topic and the post by vsloathe kinda overlap or the part where i was hinting why i build ontop of libcurl.
Speed of socket, regardless of language is all the same speed (they all are built ontop of OS sockets)
Where the killer is the allocation of strings (memory buffers etc, in python all blocks of memory is called a string).
I find this out the hard way.
Bit of background.
Company i was working for wanted built a VOIP system using speex codec.
Wisdom at the time said it have to be done in C/C++ or else u can not get speed.
Anyway i make it in python with C/C++ module. It was just as quick as C/C++ version.
And i will explain how i do it.
Basically in nutshell u have
udp packets -> internal stack -> decoder -> output and for transmission exact opposite.
i will just illustrate from internal stack you have to line up packets before they can go into decoder.
So u may have to start from byte 3 lets say and u have to join, strings etc.
In all memory managed lanugage behind the scenes it will create a new string of proper size, and destroy the old one.
So the speed loss is due to memory allocation and garbage collection (in most cases not a problem but when u pulling in 100+ packets a second).
Anyway i use approach similar to gstreamer (at time gstreamer do not exist)
when udp packets arrive i put in own memory structure.
then when it go to internal stack it just pass the pointers.
same story when it go to decoder etc.
So i just use the python like glue

.
Back to topic

So in case of like parsing http header.
When u parse the header, in each section behind the scenes the language is assigning a new string (malloc is expensive)
And worse yet, when u are done with it, the string has to be destroyed.
Because in scripting language u can not access memory directly. (not without doing any hacks

)
If u access memory directly u can get tremedous speed gain, but if something goes wrong u will bring down the entire VM.
Or if u make mistake, worse yet, u can corrupt other parts of it, and u can get wierd error which very hard to trace.