Why hash () is slower under python3.4 and python2.7

I did some performance evaluation using timeit and discovered performance degradation between python 2.7.10 and python 3.4.3. I narrowed it down to a function hash():

python 2.7.10:

>>> import timeit
>>> timeit.timeit('for x in xrange(100): hash(x)', number=100000)
0.4529099464416504
>>> timeit.timeit('hash(1000)')
0.044638872146606445

python 3.4.3:

>>> import timeit
>>> timeit.timeit('for x in range(100): hash(x)', number=100000)
0.6459149940637872
>>> timeit.timeit('hash(1000)')
0.07708719989750534

It is approximately. 40% degradation! It doesn't seem to matter if the hashed integers, floats, strings (Unicode or bytearrays), etc. degradation is about the same. In both cases, the hash returns a 64-bit integer. The above was launched on my Mac and got less degradation (20%) in the Ubuntu field.

PYTHONHASHSEED = python2.7, python "", , hash() , , python3.4

- , ? , - python3?

+4
1

hash() Python 2.7 Python 3.4

  • SipHash

:

+2

Source: https://habr.com/ru/post/1658235/


All Articles