add method to optimize a template
benchmark the difference made by optimize
use optimize in tests