On Wed, Sep 30, 2009 at 10:02 AM, Magnus Lie Hetland <[email protected]> wrote:
> On Sep 30, 2009, at 18:50, Dag Sverre Seljebotn wrote:
>
>> What do you want to store?
>
> Dang! In my editing and re-editing of the email, that disappeared :-D
>
>> Assuming one-dimensional data, either Python lists or C++ vectors,
>> I'd say.
>
> Yeah, one-dimensional data -- simply a list of ints.
>
> I'll just go for a Python list for now, then, and look into it if
> performance becomes a problem. (It's not going to be a long list, but
> it may be traversed hundreds of thousands of times, so who knows... :->)
>
> Thanks,
>
> - M
>
> --
> Magnus Lie Hetland
> http://hetland.org
>
>
> _______________________________________________
> Cython-dev mailing list
> [email protected]
> http://codespeak.net/mailman/listinfo/cython-dev
>

i normally just use python lists as well. out of curiosity, i followed
the templates instructions:
http://wiki.cython.org/WrappingCPlusPlus
for the code below.
timing on my machine, that gives:

vector append 1.19197511673
python append 6.57795596123
vector get 0.080246925354
python get 2.01052689552

so the access is a lot faster. for what a contrived micro-benchmark is worth...



def extern from "vec.h":
    ctypedef struct ivec "std::vector<int>":
        void (* push_back)(int i)
        int (* at)(int i)
    ivec ivec_new "std::vector<int>"()


def main():

    cdef ivec v = ivec_new()
    cdef int N = 100000000
    cdef unsigned int i
    import time
    t = time.time()
    for i in range(N):
        v.push_back(i)

    print "vector append", time.time() - t

    a = []
    t = time.time()
    for i in range(N):
        a.append(i)

    print "python append", time.time() - t


    t = time.time()
    for i in range(N):
        v.at(i)

    print "vector get", time.time() - t

    t = time.time()
    for i in range(N):
        a[i]

    print "python get", time.time() - t
_______________________________________________
Cython-dev mailing list
[email protected]
http://codespeak.net/mailman/listinfo/cython-dev

Reply via email to