Re: [Cython] To Add datetime.pxd to cython.cpython

2013-03-03 Thread Zaur Shibzukhov
2013/3/3 Zaur Shibzukhov szp...@gmail.com:
 2013/3/2 Stefan Behnel stefan...@behnel.de:
 Hi,

 the last pull request looks good to me now.

 https://github.com/cython/cython/pull/189

 Any more comments on it?

 As was suggested earlier, I added `import_datetime` inline function to
 initialize PyDateTime C API instead of direct usage of non-native C
 macros from datetime.h.
 Now you call `import_array ()` first in the same way as is done with `numpy`.
  This approach looks natural in the light of experience with numpy.

 I make some performance comparisons. Here example for dates.

# test_date.pyx


Here test code:

from cpython.datetime cimport import_datetime, date_new, date

import_datetime()

from datetime import date as pydate

def test_date1():
cdef list lst = []
for year in range(1000, 2001):
for month in range(1,13):
for day in range(1, 20):
d = pydate(year, month, day)
lst.append(d)
return lst


def test_date2():
cdef list lst = []
for year in range(1000, 2001):
for month in range(1,13):
for day in range(1, 20):
d = date(year, month, day)
lst.append(d)
return lst

def test_date3():
cdef list lst = []
cdef int year, month, day
for year in range(1000, 2001):
for month in range(1,13):
for day in range(1, 20):
d = date_new(year, month, day)
lst.append(d)
return lst

def test1():
l = test_date1()
return l

def test2():
l = test_date2()
return l

def test3():
l = test_date3()
return l

Here are timings:

(py32)zbook:mytests $ python -m timeit -n 50 -r 5 -s from
mytests.test_date import test1 test1()
50 loops, best of 5: 83.2 msec per loop
(py32)zbook:mytests $ python -m timeit -n 50 -r 5 -s from
mytests.test_date import test2 test2()
50 loops, best of 5: 74.7 msec per loop
(py32)zbook:mytests $ python -m timeit -n 50 -r 5 -s from
mytests.test_date import test3 test3()
50 loops, best of 5: 20.9 msec per loop

OSX 10.6.8 64 bit python 3.2

Shibzukhov Zaur
___
cython-devel mailing list
cython-devel@python.org
http://mail.python.org/mailman/listinfo/cython-devel


Re: [Cython] Py_UNICODE* string support

2013-03-03 Thread Stefan Behnel
Stefan Behnel, 03.03.2013 20:41:
 Nikita Nemkin, 03.03.2013 14:40:
 Please reconsider your decision wrt C-level literals.
 I believe that nogil code and a bit of efficiency (on 3.3) justify their
 existence. (char* literals do have C-level literals, Py_UNICODE* is in
 the same basket when it comes to Windows code).
 The code to support them is also small and well-contained.
 I've updated my pull request to fully support for non-BMP Py_UNICODE[]
 literals.
 
 Ok, I think it's ok now. I can accept the special casing of Py_UNICODE
 literals, it actually adds a value.
 
 As one little nit-pick, may I ask you to rename the new name references to
 unicode into py_unicode in your code? For example, is_unicode,
 get_unicode_const, unicode_const_index, etc. Given that Py_UNICODE is
 no longer the native equivalent of Python's unicode type in Py3.3, I'd like
 to avoid confusion in the code. The name unicode is much more likely to
 refer to the builtin Python type than to a native C type when it appears in
 Cython's sources.

Oh, and yet another thing: could you write up some documentation for this
in docs/src/tutorial/strings.rst ? Basically a Windows/wchar_t related
section, that also warns about the inefficiency in Py3.3, so that users
don't accidentally assume it's efficient for anything that needs to be
portable.

Stefan

___
cython-devel mailing list
cython-devel@python.org
http://mail.python.org/mailman/listinfo/cython-devel


Re: [Cython] To Add datetime.pxd to cython.cpython

2013-03-03 Thread Zaur Shibzukhov
2013/3/3 Zaur Shibzukhov szp...@gmail.com:
 2013/3/3 Zaur Shibzukhov szp...@gmail.com:
 2013/3/3 Zaur Shibzukhov szp...@gmail.com:
 2013/3/2 Stefan Behnel stefan...@behnel.de:
 Hi,

 the last pull request looks good to me now.

 https://github.com/cython/cython/pull/189

 Any more comments on it?

 As was suggested earlier, I added `import_datetime` inline function to
 initialize PyDateTime C API instead of direct usage of non-native C
 macros from datetime.h.
 Now you call `import_array ()` first in the same way as is done with 
 `numpy`.
  This approach looks natural in the light of experience with numpy.

  I make some performance comparisons. Here example for dates.

 # test_date.pyx
 

 Here test code:

 from cpython.datetime cimport import_datetime, date_new, date

 import_datetime()

 from datetime import date as pydate

 def test_date1():
 cdef list lst = []
 for year in range(1000, 2001):
 for month in range(1,13):
 for day in range(1, 20):
 d = pydate(year, month, day)
 lst.append(d)
 return lst


 def test_date2():
 cdef list lst = []
 for year in range(1000, 2001):
 for month in range(1,13):
 for day in range(1, 20):
 d = date(year, month, day)
 lst.append(d)
 return lst

 def test_date3():
 cdef list lst = []
 cdef int year, month, day
 for year in range(1000, 2001):
 for month in range(1,13):
 for day in range(1, 20):
 d = date_new(year, month, day)
 lst.append(d)
 return lst

 def test1():
 l = test_date1()
 return l

 def test2():
 l = test_date2()
 return l

 def test3():
 l = test_date3()
 return l

 Here are timings:

 (py32)zbook:mytests $ python -m timeit -n 50 -r 5 -s from
 mytests.test_date import test1 test1()
 50 loops, best of 5: 83.2 msec per loop
 (py32)zbook:mytests $ python -m timeit -n 50 -r 5 -s from
 mytests.test_date import test2 test2()
 50 loops, best of 5: 74.7 msec per loop
 (py32)zbook:mytests $ python -m timeit -n 50 -r 5 -s from
 mytests.test_date import test3 test3()
 50 loops, best of 5: 20.9 msec per loop

 OSX 10.6.8 64 bit python 3.2


 More acurate test...

 # coding: utf-8

 from cpython.datetime cimport import_datetime, date_new, date

 import_datetime()

 from datetime import date as pydate

 def test_date1():
 cdef list lst = []
 cdef int year, month, day
 for year in range(1000, 2001):
 for month in range(1,13):
 for day in range(1, 20):
 d = pydate(year, month, day)
 lst.append(d)
 return lst


 def test_date2():
 cdef list lst = []
 cdef int year, month, day
 for year in range(1000, 2001):
 for month in range(1,13):
 for day in range(1, 20):
 d = date(year, month, day)
 lst.append(d)
 return lst

 def test_date3():
 cdef list lst = []
 cdef int year, month, day
 for year in range(1000, 2001):
 for month in range(1,13):
 for day in range(1, 20):
 d = date_new(year, month, day)
 lst.append(d)
 return lst

 def test1():
 l = test_date1()
 return l

 def test2():
 l = test_date2()
 return l

 def test3():
 l = test_date3()
 return l

 Timings:

 (py32)zbook:mytests $ python -m timeit -n 50 -r 5 -s from
 mytests.test_date import test1 test1()
 50 loops, best of 5: 83.3 msec per loop
 (py32)zbook:mytests $ python -m timeit -n 50 -r 5 -s from
 mytests.test_date import test2 test2()
 50 loops, best of 5: 74.6 msec per loop
 (py32)zbook:mytests $ python -m timeit -n 50 -r 5 -s from
 mytests.test_date import test3 test3()
 50 loops, best of 5: 20.8 msec per loop

Yet another performance comparison for `time`:

# coding: utf-8

from cpython.datetime cimport import_datetime, time_new, time

import_datetime()

from datetime import time as pytime

def test_time1():
cdef list lst = []
cdef int hour, minute, second, microsecond
for hour in range(0, 24):
for minute in range(0,60):
for second in range(0, 60):
for microsecond in range(0, 10, 5):
d = pytime(hour, minute, second, microsecond)
lst.append(d)
return lst


def test_time2():
cdef list lst = []
cdef int hour, minute, second, microsecond
for hour in range(0, 24):
for minute in range(0,60):
for second in range(0, 60):
for microsecond in range(0, 10, 5):
d = time(hour, minute, second, microsecond)
lst.append(d)
return lst

def test_time3():
cdef list lst = []
cdef int hour, minute, second, microsecond
for hour in range(0, 24):
for minute in range(0,60):
for second in range(0, 60):
for microsecond in range(0,