Important Notice: Our web hosting provider recently started charging us for additional visits, which was unexpected. In response, we're seeking donations. Depending on the situation, we may explore different monetization options for our Community and Expert Contributors. It's crucial to provide more returns for their expertise and offer more Expert Validated Answers or AI Validated Answers. Learn more about our hosting issue here.

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?

0
Posted

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?

0

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.

Related Questions

What is your question?

*Sadly, we had to bring back ads too. Hopefully more targeted.

Experts123