Optimisation problem - in C?

Tim Churches tchur at optushome.com.au
Tue Feb 20 14:41:43 EST 2001


After a bit of profiling I have worked out exactly which part of a data
crunching class on which I am working needs to be optimised - maybe in
C? The abstracted function which needs to run faster is as follows - not
surprisingly it is itself a loop which lives within two other loops -
hence it is called rather frequently:

############
def makevector(sourcelist,elementlist):
	resultvector = []
	for element in elementlist:
		resultvector.append(sourcelist[element])
	return resultvector
###########

My test data has about 300,000 elements in sourcelist and between about
10,000 and 70,000 elements in elementlist, but larger lists are
envisaged, hence the earnest desire for maximum speed.

Questions:
Can this function (which essentially does the fairly generic operation
of "fetch the elements of sequence a using the element indexes contained
in sequence b") be optimised without resorting to a C module?

If not, is anyone willing to hold my hand (it's clean, but rather
sweaty) while I fumble with trying to replace the function with a C
module? (Note: after years of unremitting effort, I have finally
mastered all aspects of hello_world.c)

Tim Churches
Sydney, Australia




More information about the Python-list mailing list