Performance : should we make our calculs in templates with xen:calc, or in PHP ?

Jean-Baptiste

Well-known member
Hello,

I need to make a lot of calcs, but I wanted to know what would be the faster way : doing that with xen:calc in templates, or doing the calcs with normal PHP operators in my model/controller ?

Best regards.
 
It's the same.

XenForo compiles templates containing various bits of xen: syntax and other stuff into a compiled and executable PHP script.

An example is if you create a template (let's call it test_1) with contents:

Code:
{xen:calc '1 + 1'}

That is saved in the xf_template table.

If you check xf_template_compiled table and find the test_1 template:

PHP:
$__output = '';
$__output .= (1 + 1);

The template compiler has literally taken the xen syntax and converted it into the PHP equivalent:

(1 + 1)

So effectively whether you do the calc in the template or whether you use PHP functions it's the same.
 
It's the same.

XenForo compiles templates containing various bits of xen: syntax and other stuff into a compiled and executable PHP script.

An example is if you create a template (let's call it test_1) with contents:

Code:
{xen:calc '1 + 1'}

That is saved in the xf_template table.

If you check xf_template_compiled table and find the test_1 template:

PHP:
$__output = '';
$__output .= (1 + 1);

The template compiler has literally taken the xen syntax and converted it into the PHP equivalent:

(1 + 1)

So effectively whether you do the calc in the template or whether you use PHP functions it's the same.

Thanks you very much Chris, I wanted to make sur it's the exact same :)
 
Back
Top Bottom