juldayPerfΒΆ

Performance check

''' Performance check

'''
import timeit

if __name__ == '__main__':

    setup='''
from julday import Julday
def comparison():
    jd0 = Julday(2009, 1, 30, 0, 0, 0)
    jd1 = Julday(2010, 1, 30, 0, 0, 0)
    jd0 == jd1
    jd1 < jd0
    jd0 > jd1
'''

    setup2='''
from julday import Julday, JdSeries
import random
def sorting():
    jds = JdSeries()
    for i in range(1000):
        jd = Julday(2009, 1, 1, 0, 0, 0).dayAfter(random.random())
        if not jds.hasElement(jd):
            jds.add(jd, i)
#    return jds.getJuldayList()
    return jds.getJdList()
'''

    ### This is a sample file to use datetime instead of julyda
    setup3='''
from datetime import datetime as t
from datetime import timedelta as dt
import random
def sorting():
    ts = []
    t0 = t(2009, 1, 1, 0, 0, 0)
    for i in range(10000):
        rnd = random.random() * 86400000
        d = dt(days = int(rnd / 1000), seconds = (rnd / 1000) % 86400 )
        ts.append(t0+d)
    sorted(ts)
'''

    # 1000 comparison

    #t=timeit.Timer("comparison", setup)
    #print t.timeit(1)
    #print t.repeat(3, 1000)

    t=timeit.Timer("sorting()", setup2)
    print(t.timeit(1))
    print(t.repeat(3, 10))

    #t=timeit.Timer("sorting()", setup3)
    #print t.timeit(1)
    #print t.repeat(3, 10)