P
P
power mind2018-03-09 17:42:07
Python
power mind, 2018-03-09 17:42:07

Why is a+b faster than a.__add__(b)?

>>> from timeit import timeit
>>> timeit('''
... a = 10
... b = 5
... c = a + b
... ''')
0.24442141791507765
>>> timeit('''
... a = 10
... b = 5
... c = a.__add__(b)
... ''')
0.5271954476593237
>>>

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question