title: Performance impact of Python classes: Scientific Computing
body: <p>So I'm in the process of writing a particle model. This simulation will involve creating a number of particles with attributes like species index (to identify particle type), and position/velocity in 3D space. It will also have properties based on it's position within the space that will be calculated during the simulation run. I've previously been running this models using a giant numpy array, where each row corresponds to a single particle, and each column a particle attribute.</p>
  
  <p>My main question is this: If I was to create a class "Particles" so that I could generate instances representing each particle, is there a performance hit in terms of computational speed? If I wanted to run a program with a million particles, is it more efficient to have all the numbers in one big array (even though it's not quite as readable), or is it just as efficient to use instances of this class, and modify the instance attributes as the simulation progresses? Or is it that the classes are fine, but storing that many class instances in a Python list/NumPy array really slows down the execution? </p>
  
  <p>As an aside, this program will be used with the python module "Numba" that has a great deal of optimization for numerical computation (specifically via things like the jitclass <a href="http://numba.pydata.org/numba-doc/latest/user/jitclass.html#numba.jitclass" rel="nofollow noreferrer">http://numba.pydata.org/numba-doc/latest/user/jitclass.html#numba.jitclass</a>). However, I don't want to destroy the performance benefits of this module by declaring variables in my simulation that cause it to run inefficiently. </p>
  
  <p>Thanks!</p>