You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This patch special-cases indexing of tuples and lists by a PyLong: heeres/cpython@ade7269
Benchmark using:
import timeit
def x():
a = list(range(16))
for j in range(10000):
a[j%16]
print('%.01f ms' % (timeit.timeit(x, number=1000)*1000))
As baseline, the loop with a pass instruction is timed at 120ms.
Without the patch, time is 446ms (456ms) with a defined as a tuple (list)
With the suggested patch, time is about 325ms for both tuple/list. Subtracting the time for the loop with a pass, this means the indexing is performed about 35% faster. Since we're not accounting for the modulo operation in this calculation, my guess would be somewhere between 40-45%.
The culprit is the rather complex PyNumber_AsSsize_t function, which performs a few calls and some reference juggling even in case of a simple PyLong.
If the digit size would be increased, the fastest path could apply to even more cases than it does now.
The text was updated successfully, but these errors were encountered:
This patch special-cases indexing of tuples and lists by a PyLong: heeres/cpython@ade7269
Benchmark using:
As baseline, the loop with a
pass
instruction is timed at 120ms.Without the patch, time is 446ms (456ms) with
a
defined as a tuple (list)With the suggested patch, time is about 325ms for both tuple/list. Subtracting the time for the loop with a
pass
, this means the indexing is performed about 35% faster. Since we're not accounting for the modulo operation in this calculation, my guess would be somewhere between 40-45%.The culprit is the rather complex PyNumber_AsSsize_t function, which performs a few calls and some reference juggling even in case of a simple PyLong.
If the digit size would be increased, the fastest path could apply to even more cases than it does now.
The text was updated successfully, but these errors were encountered: