Do you know where your variables are? | |
PerlMonks |
I know two prints are slower than one, but 200x slower?!?!?by rsmah (Scribe) |
on Aug 16, 2007 at 00:23 UTC ( [id://632891]=perlquestion: print w/replies, xml ) | Need Help?? |
rsmah has asked for the wisdom of the Perl Monks concerning the following question: I was doing a bit of experimenting with writing a socket server and found some weird behavior that I just don't understand. I have a simple forking server that echo's data back to the client. Connections are persistent, multiple requests can take place over a single connection. The client simply opens a connection, sends a line of text, reads lines back until a period -- repeats this many times -- and then exits. When server.pl prints its output to the client using 1 print statement, it's lickety split fast. When it uses 2 or more print statements, it's dead slow. Not just a little slower, over 100x slower! I can't understand why. Let's run a test using a single print statement in the server (the arg 1 means use 1 print statement):
And now using 2 print statements:
That's about 245 times slower! Now, I'd expect it to be a bit slower, and I could even accept 2x or 5x slower, but 200x times slower?!?! This just makes no sense to me. Can someone who understands how the perl stdio layer interacts with TCP sockets on Linux explain this? A few notes that might help:
And finally, here's my stupid simple code: The server.pl is:The client.pl is:
Back to
Seekers of Perl Wisdom
|
|