I like to work with classes and methods instead of bare functions. I am wondering if there is a specific performance impact to do so (either in execution speed, or memory usage or in other aspects).
A quick test shows that both perform equally well:
import timeit
class Hello:
def hello(self):
x = 9 * 8 + 3**5
def world():
x = 9 * 8 + 3 ** 5
print(timeit.timeit(world, number=10000000))
h = Hello()
print(timeit.timeit(h.hello, number=10000000))
# 0.8460009839758439
# 0.8781686117747095
In other tests I did not see the RAM being used more in one case than in the other.
Are there specific cases where performance will be degraded when using a class/method instead of a function?
Note: I would like to focus exclusively on code performance, not aesthetical aspects