I think that using each of them is too subjective for me to do this, so I will just stick to the numbers.
I compared the time it takes to create and change a variable in the dict, new_style class and the new_style class with slots.
Here is the code I used to test it (it's a little dirty, but it does the job.)
import timeit class Foo(object): def __init__(self): self.foo1 = 'test' self.foo2 = 'test' self.foo3 = 'test' def create_dict(): foo_dict = {} foo_dict['foo1'] = 'test' foo_dict['foo2'] = 'test' foo_dict['foo3'] = 'test' return foo_dict class Bar(object): __slots__ = ['foo1', 'foo2', 'foo3'] def __init__(self): self.foo1 = 'test' self.foo2 = 'test' self.foo3 = 'test' tmit = timeit.timeit print 'Creating...\n' print 'Dict: ' + str(tmit('create_dict()', 'from __main__ import create_dict')) print 'Class: ' + str(tmit('Foo()', 'from __main__ import Foo')) print 'Class with slots: ' + str(tmit('Bar()', 'from __main__ import Bar')) print '\nChanging a variable...\n' print 'Dict: ' + str((tmit('create_dict()[\'foo3\'] = "Changed"', 'from __main__ import create_dict') - tmit('create_dict()', 'from __main__ import create_dict'))) print 'Class: ' + str((tmit('Foo().foo3 = "Changed"', 'from __main__ import Foo') - tmit('Foo()', 'from __main__ import Foo'))) print 'Class with slots: ' + str((tmit('Bar().foo3 = "Changed"', 'from __main__ import Bar') - tmit('Bar()', 'from __main__ import Bar')))
And here is the result ...
Creature...
Dict: 0.817466186345 Class: 1.60829183597 Class_with_slots: 1.28776730003
Variable change ...
Dict: 0.0735140918748 Class: 0.111714198313 Class_with_slots: 0.10618612142
So, if you just save variables, you need speed, and you don’t need a lot of calculations, I recommend using dict (you can always just make a function that looks like a method). But, if you really need classes, remember - always use __ slots __ .
Note:
I tested a class with classes and new_style and old_style. It turns out that old_style classes are faster to create, but slower to modify (but not by much, but significantly if you create many classes in a narrow loop (hint: you are doing it wrong)).
Also, the time it takes to create and modify variables may vary on your computer, as it is my old and slow one. Make sure you check it yourself to see the "real" results.
Edit:
I later tested namedtuple: I can't change it, but it took 1.4 seconds to create 10,000 samples (or something like that), so the dictionary is really the fastest.
If I change the dict function to include keys and values and return dict instead of the variable containing dict, when I create it, it gives me 0.65 instead of 0.8 seconds.
class Foo(dict): pass
Creating is like a class with slots, and changing the variable is the slowest (0.17 seconds), so these classes are not used . switch to dict (speed) or for a class derived from an object ("syntax candy")