DEV Community

Discussion on: Consume 50% less memory with your Python objects

Collapse
 
naruaika profile image
Naufan Rusyda Faikar

I'm curious, how about the access performance? Could you do the measurement for me as I'm not a Python developer, but rather someone interested in Python?

Collapse
 
jeromek13 profile image
Jérôme Krell • Edited

Hey
There is also a performance gain when accessing / initializing the Object, see example. Hope that answers your question

import timeit
print(timeit.timeit("p3 = SmallObject('Jerome', 'K')", "from __main__ import SmallObject")) 
# Output: 0.13634319999982836
print(timeit.timeit("p3 = BiggerObject('Jerome', 'K')", "from __main__ import BiggerObject")) 
# Output: 0.166356599998835
Enter fullscreen mode Exit fullscreen mode