I notice that in a zope application that I have to maintain is slow because of DateTime class.
The profile in this application test give the top time to this class.
So I want to test an other implementation which is name mx.DateTime. The difference is that mx.DateTime is writen in C.
So in a terminal , I install the two eggs via easy install :
./bin/easy_install DateTime ./bin/easy_install egenix-mx-base
And do a little script for testing the two api:
import sys
from mx import DateTime as mxDateTime
from DateTime import DateTime
from datetime import datetime
from time import time
def create_mxdatetime():
return mxDateTime.now()
def create_zopedatetime():
return DateTime()
def create_datetime():
return datetime.now()
def bf(f, i):
t1 = time()
for i in xrange(i):
f()
t2 = time()
print "bench for %s is %s" % (str(f), t2 - t1)
bf(create_mxdatetime, int(sys.argv[1]))
bf(create_zopedatetime, int(sys.argv[1]))
bf(create_datetime, int(sys.argv[1]))
This script just create Date in the three implementation : zope, mx and the standard library
And the results:
bash-3.2$ bin/python bench.py 1000 bench for function create_mxdatetime at 0x7db70 is 0.00120091438293 bench for function create_zopedatetime at 0x4215f0 is 0.84446310997 bench for function create_datetime at 0x4214b0 is 0.00220394134521 bash-3.2$ bin/python bench.py 10000 bench for function create_mxdatetime at 0x7db70 is 0.0117778778076 bench for function create_zopedatetime at 0x4215f0 is 8.81699991226 bench for function create_datetime at 0x4214b0 is 0.041069984436 bash-3.2$ bin/python bench.py 100000 bench for function create_mxdatetime at 0x7db70 is 0.11746096611 bench for function create_zopedatetime at 0x4215f0 is 87.8845770359 bench for function create_datetime at 0x4214b0 is 0.222129106522
No comment.. and in memory ?
So
bash-3.2$ bin/easy_install pympler
and now::
>>> from pympler import asizeof >>> from datetime import datetime >>> from mx import DateTime as mxDateTime >>> from DateTime import DateTime >>> asizeof.asizesof(DateTime() , mxDateTime.now(), datetime.now()) (1760, 56, 32)
Hoaaa !! a zope DateTime is 798 time slower than mxDateTime and it consume 31 more space than mxDateTime
I think ReplacingDateTime could be a good performance issue for zope, no ?
With DateTimeNG (zope DateTime with mx.DateTime) performance is 10 time better than DateTime. Memory consume is the same
From mx.DateTime documentation
Comparing the types to time-module based routines is not really possible,
since the used strategies differ. You can compare them to tuple-based
date/time classes though: DateTime[Delta] are much faster on creation, use
less storage and are faster to convert to the supported other formats than
any equivalent tuple-based implementation written in Python.
Creation of time-module values using time.mktime() is much slower than
doing the same thing with DateTime(). The same holds for the reverse
conversion (using time.localtime()).
The storage size of ticks (floats, which the time module uses) is about 1/3
of the size a DateTime instance uses. This is mainly due to the fact that
DateTime instances cache the broken down values for fast access.
To summarize: DateTime[Delta] are faster, but also use more memory than
traditional time-module based techniques.




