User login

Use echo instead of print in themes for speed?

Hat tip to RobLoach who noted this in the #drupal IRC channel-- if we want to squeeze hundredths of a millisecond more out of our Drupal modules and themes, we should use echo instead of print for getting the data to the screen.

UPDATE: The PHP developers don't recommend switching from print to echo for speed reasons, suggesting that the difference can be dependent on the setup of your environment.

Random more useful PHP code speed improvements:

Best to not rely on include_path:
Good: include("./file.php"); // Looks for the file in the current working directory.
Bad: include("file.php"); // Searches every directory in include_path.

Using include_once and require_once is also much slower than include and require.

Use an opcode cache.

References

http://www.learnphponline.com/php-basics/php-echo-vs-print

http://ilia.ws/files/phptek2007_performance.pdf
http://ilia.ws/files/phpquebec_2009.pdf

Searched words: 
Drupal theming performance print statement faster than echo

Comments

Post new comment

The content of this field is kept private and will not be shown publicly.
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.
  • You can use Markdown syntax to format and style the text. Also see Markdown Extra for tables, footnotes, and more.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <img> <blockquote> <small> <h2> <h3> <h4> <h5> <h6> <sub> <sup> <p> <br> <strike> <table> <tr> <td> <thead> <th> <tbody> <tt> <output>
  • Lines and paragraphs break automatically.

More information about formatting options

By submitting this form, you accept the Mollom privacy policy.