Florent Aide a écrit :
> This will give you the time your method (in my example index) took. It
> will not give you the full-stack execution.
>
> But this will be the same as what you get on many (all?) PHP-based sites. :)
>
> Florent.
>
>
You could setup a decorator to calculate this deltatime and add it just
under the @expose so you'll get a little more than just your method
execution time...
something like
def generation_time():
def decorator(func):
def wrapper(*params, **kw):
t1 = time.time()
result = func(*params, **kw)
t2 = time.time()
result['elapsed_time'] = t2 - t1
return result
return wrapper
return decorator
...
@expose()
@generation_time()
@validate(...)
@error_hadler(...)
def xxx(self):
.....
> On 3/5/07, Mikkel Høgh <[EMAIL PROTECTED]> wrote:
>
>> But isn't that only part of the picture? Does the controller code
>> actually get loaded first on a request?
>>
>> On Mar 5, 8:55 pm, "Florent Aide" <[EMAIL PROTECTED]> wrote:
>>
>>> You can also do the same with
>>> import time
>>> t1 = time.time()
>>> t2 = time.time()
>>> elapsed_time = t2 - t1
>>>
>>> in this case elapsed_time is a float expressed in seconds.
>>>
>>> Cheers.
>>>
>>> On 3/5/07, Florent Aide <[EMAIL PROTECTED]> wrote:
>>>
>>>
>>>> On 3/5/07, Mikkel Høgh <[EMAIL PROTECTED]> wrote:
>>>>
>>>>> Hi guys,
>>>>>
>>>> Hi Mikkel,
>>>>
>>>>> I was wondering wheter it is possible to output the page generation
>>>>> time, like many PHP-based sites do.
>>>>> It is great to get an overview how wasteful your code is :)
>>>>>
>>>> import datetime
>>>>
>>>> class Root(controllers.RootController):
>>>> @expose(template="tmc.templates.welcome")
>>>> def index(self):
>>>> t1 = datetime.datetime.now()
>>>> #do some stuff here
>>>> t2 = datetime.datetime.now()
>>>> elapsed_time = t2 - t1
>>>> return dict(elapsed_time=elapsed_time)
>>>>
>>>> elapsed_time is a timedelta. You can use its attributes to have the
>>>> seconds and microseconds elapsed. ie:
>>>>
>>>> elapsed_time.seconds
>>>> elapsed_time.microseconds
>>>>
>>>> you can even have days but hopefully it will return 0 :)
>>>>
>>>> assert elapsed_time.days == 0, "Houston we got a problem here..."
>>>>
>>>> Regards,
>>>>
>>>> Florent AIDE.
>>>>
>>
>
> >
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"TurboGears" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/turbogears?hl=en
-~----------~----~----~----~------~----~------~--~---