On Wed, Jan 22, 2014 at 3:31 PM, Arnon Marcus <a.m.mar...@gmail.com> wrote:

> What I am interested in doing, is have it turned back into a datetime
object
> when 'decoding' - and THAT is not supported even in the web2py flavor -
and
> I haven't found a single simple solution for it on the web for the
standard
> simplejson either.
>
> I tried to hack it in the redis_cache.py (since I use redis for caching).
I
> added a function 'as_datetime' at the beginning of the file:
>
> def as_datetime(dct):
>     if type(dct) is dict:
>         Created = dct.get('Created', None)
>         Modified = dct.get('Modified', None)
>         if Created: dct['Created'] = datetime.datetime.strptime(Created,
> '%Y-%m-%d %H:%M:%S')
>         if Modified: dct['Modified'] =
datetime.datetime.strptime(Modified,
> '%Y-%m-%d %H:%M:%S')
>     return dct
>

> The problem I'm having is that this is all very 'taxing' on my
> caching-system - I am getting a slowdown of 40% on the entire
> cache-retrieval on each request, compared to leaving it as a string...
>

I believe the bottle neck is in the datetime.datetime.strptime function.

I attached some tests comparing some alternatives to your as_datetime
function

Here are my results running as_datetime.py bechmark script attached.


  0 original Arnon version             0.854146957397
 1 almost original                    0.836435079575
 2 isinstance                         0.842170953751
 3 strptime in globals                0.814795970917
 4 simple parser (no strptime)        0.182478904724
 5 regex parser (no strptime)         0.198482990265
 6 cython simple parser (no strptime) 0.0408730506897

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Attachment: as_datetime.tar.gz
Description: GNU Zip compressed data

Reply via email to