On Wed, Sep 30, 2009 at 12:22 PM, Stefan Behnel <[email protected]> wrote:
>
> Brent Pedersen wrote:
>> timing on my machine, that gives:
>>
>> vector append 1.19197511673
>> python append 6.57795596123
>> vector get 0.080246925354
>> python get 2.01052689552
>
> Note: if you provide the correct types for the C++ code, you should do the
> same thing for the Cython code. Typing the list "a" as "cdef list a" should
> give you better performance here, for both a.append() and a[i].

aye, thanks, i forgot. but it doesnt seem to change the times by more than 10%.
here's the generated code for getitem for both cases. (in the latter,
it's casting the list to a PyObject .)


#################
a = []
################

 *         a[i]             # <<<<<<<<<<<<<<
 *
 *     print "python get: %.4f" % (time.time() - t)
 */
    __pyx_1 = __Pyx_GetItemInt(__pyx_v_a, __pyx_v_i, sizeof(int),
PyInt_FromLong); if (!__pyx_1) {__pyx_filename = __pyx_f[0];
__pyx_lineno = 82; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_1);
    __Pyx_DECREF(__pyx_1); __pyx_1 = 0;

##################
cdef list a = []
##################

 *         a[i]             # <<<<<<<<<<<<<<
 *
 *     print "python get: %.4f" % (time.time() - t)
 */
    __pyx_1 = __Pyx_GetItemInt_List(((PyObject *)__pyx_v_a),
__pyx_v_i, sizeof(int), PyInt_FromLong); if (!__pyx_1) {__pyx_filename
= __pyx_f[0]; __pyx_lineno = 82; __pyx_clineno = __LINE__; goto
__pyx_L1_error;}
    __Pyx_GOTREF(__pyx_1);
    __Pyx_DECREF(__pyx_1); __pyx_1 = 0;



>
> You can also look at the generated C++ code to see how it shrinks.
>
> Stefan
>
> _______________________________________________
> Cython-dev mailing list
> [email protected]
> http://codespeak.net/mailman/listinfo/cython-dev
>
_______________________________________________
Cython-dev mailing list
[email protected]
http://codespeak.net/mailman/listinfo/cython-dev

Reply via email to