Forum: Poser Python Scripting


Subject: Faster operation on a list of vectors?

damir_prebeg opened this issue on Jan 17, 2007 ยท 5 posts


bagginsbill posted Mon, 22 January 2007 at 9:54 AM

Curious. There must be more to this than you told us. Unless you define "ages" to be 4.5 milliseconds, I'm very confused by your results. The following script sets up a 20000 element array of sets that are to be performed on the target array. It measures the time it takes to do the sets, and in Poser 6 on my PC it averages about 4.5 milliseconds.

I did one tiny optimization, which is to have the "for" loop break the set up already using tuple assignment so I don't have to do the subscripting of vec[0] and vec[1].

# make 20000 copies of [0, [1,2,3]]
sets = [[0, [1,2,3]]] * 20000
# make a 30000 element array
target = [None] * 30000

# get access to hi-res timer
from time import clock

# function to do the test
def test(a, b):
        # get current time
        t = clock()
        for v0,v1 in a:
                b[v0] = v1
        # calculate delta time
        t = clock() - t
        # print time (in milliseconds)
        print t * 1000

test(sets, target)

Renderosity forum reply notifications are wonky. If I read a follow-up in a thread, but I don't myself reply, then notifications no longer happen AT ALL on that thread. So if I seem to be ignoring a question, that's why. (Updated September 23, 2019)