Last active
June 26, 2017 08:02
-
-
Save 5j9/4fe0dbe7e6b3dac03871a7d53b5249d9 to your computer and use it in GitHub Desktop.
Python's khayyam vs jdatetime performance comparison
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from jdatetime import date as jd, GregorianToJalali, JalaliToGregorian | |
import khayyam, jdatetime | |
from khayyam import JalaliDate | |
from datetime import date | |
from timeit import timeit | |
print('khayyam.__version__:', khayyam.__version__) | |
print('jdatetime.__VERSION__:', jdatetime.__VERSION__) | |
print('Jalali to Gregorian:') | |
k = JalaliDate(1378, 4, 18).todate() | |
j = jd(1378, 4, 18).togregorian() | |
assert j == k | |
j = JalaliToGregorian(1378, 4, 18) | |
assert (j.gyear, j.gmonth, j.gday) == (k.year, k.month, k.day) | |
print( | |
'khayyam.JalaliDate:\t', | |
timeit( | |
'k=JalaliDate(1365, 3, 28).todate();k.year, k.month, k.day', | |
globals=globals(), | |
number=10**5 | |
) | |
) | |
print( | |
'jdatetime.JalaliToGregorian:\t', | |
timeit( | |
'j=JalaliToGregorian(1378, 4, 18);j.gyear, j.gmonth, j.gday', | |
globals=globals(), | |
number=10**5 | |
) | |
) | |
print('Gregorian to Jalali:') | |
g = date(1999, 7, 9) | |
k = JalaliDate(g) | |
j = GregorianToJalali(1999, 7, 9) | |
assert (j.jyear, j.jmonth, j.jday) == (k.year, k.month, k.day) | |
print( | |
'khayyam.JalaliDate:\t', | |
timeit( | |
'k=JalaliDate(g);k.year, k.month, k.day', | |
globals=globals(), | |
number=10**5 | |
) | |
) | |
print( | |
'jdatetime.JalaliToGregorian:\t', | |
timeit( | |
'j=GregorianToJalali(1999, 7, 9);j.jyear, j.jmonth, j.jday', | |
globals=globals(), | |
number=10**5 | |
) | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Running on linux (the C extension of khayyam is installed):