views:

230

answers:

3

Basically I am storing millions of vector3 values in a list. But right now the vector3s are defined like so:

[5,6,7]

which I believe is a list. The values will not be modified nor I need any vector3 functionality.

Is this the most performant way to do this?

+6  A: 

The best way is probably using tuples rather than a list. Tuples are faster than lists, and cannot be modified once defined. http://docs.python.org/tutorial/datastructures.html#tuples-and-sequences

edit: more specifically, probably a list of tuples would work best: [(4,3,2), (2,4,5)...]

jacobangel
+4  A: 

Traditionally, you would profile your code, find bottlenecks, and deal with them as required. The answer is "No it probably isn't the most performant way" but does that really matter? It might do, and when it does, it can be fixed.

Ali A
+11  A: 

If you are storing millions of them, the best way (both for speed and memory use) is to use numpy.

If you want to avoid numpy and use only built-in python modules, using tuples instead of lists will save you some overhead.

dF
Ahem. If not using numpy, use the `array` module.
kaizer.se