My script makes many calls to print, and PerlEx does not seem to be a lot faster than regular Perl CGI when running it. How do I optimize print() performance?
Outputting data is a relatively expensive operation, whether it is a regular Perl CGI script, or one running under PerlEx. While most scripts will not be affected to any significant degree by this fact, any Perl script that performs many calls to print will see an increase in speed by gathering as much data as possible before calling print. Perl makes this easy by providing the ‘.=’ operator. For example, if the following code: $data = “Hello”; print $data; $data = ” world”; print $data; $data = “\n”; print $data; is rewritten as: $data = “Hello”; $data .= ” world”; $data .= “\n”; print $data; it will execute faster, whether it is running with Perl or PerlEx. An additional point to note is that PerlEx output is unbuffered–every print statement results in output from the web server. While this gives the programmer precise control over what gets sent from the web server, it also imposes a slight penalty on execution time when many print statements are used in a script.