[Zope] page templates and "python:"

Claudio Battaglino c.battaglino at metaware.it
Mon Jul 3 11:11:14 EDT 2006


Andreas Jung ha scritto:

>
>
> --On 3. Juli 2006 15:38:58 +0200 Claudio Battaglino 
> <c.battaglino at metaware.it> wrote:
>
>> Jens Vagelpohl ha scritto:
>>
>>>
>> Could it be that, using a Python expression, I have an overhead because
>> Zope loads a Python interpreter each time it finds a "python:"?
>> If this is true then it is better to use path expression, if possible.
>>
>
> nah....Python expression are executed in a sandbox (RestrictedPython) 
> which will introduce additional overhead..but let numbers 
> speak...write a loop in TAL and compare the performance of path 
> expressions vs. python expressions... don't guess, but measure...
>
> -aj

It seems that the Python Expression works a bit better:

To the test this, I used these two Page Templates and PTProfiler:

PATH EXPRESSION 
    <div tal:define="test_user here/portal_membership/getAuthenticatedMember" tal:repeat="counter python:range(5000)">
      <span tal:content="test_user/getId" />
    </div>

PYTHON EXPRESSION
    <div tal:define="test_user here/portal_membership/getAuthenticatedMember" tal:repeat="counter python:range(5000)">
      <span tal:content="python: test_user.getId()" />
    </div>

PATH EXPRESSION 
Expression - Total time - Number of calls - Time per call
path: test_user/getId  	0.72  	5000  	0.00014
path: test_user/getId  	0.63  	5000  	0.00013
path: test_user/getId  	0.72  	5000  	0.00014

path: test_user/getId  	4.0  	50000  	8e-05
path: test_user/getId	4.09	50000	8e-05
path: test_user/getId  	4.12  	50000  	8e-05

PYTHON EXPRESSION
Expression - Total time - Number of calls - Time per call
python: test_user.getId()  	0.6  	5000  	0.00012
python: test_user.getId()  	0.51  	5000  	0.0001
python: test_user.getId()  	0.48  	5000  	0.0001
python: test_user.getId()  	3.19  	50000  	6e-05
python: test_user.getId()  	3.42  	50000  	7e-05
python: test_user.getId()  	2.96  	50000  	6e-05

Is it a  significant test?

claudio :-)



More information about the Zope mailing list