Use a templating engine


Templating engines, like Smarty and Twig, almost always provide a system for caching compiled templates in a binary file containing an intermediate code called bytecode.
This often considerably reduces CPU usage, especially when an intermediate code cache is added to the templating engine’s cache system.

To enable caching in Smarty:

$smarty = new Smarty;
$smarty->caching = 1;