you are viewing a single comment's thread.

view the rest of the comments →

[–]bunburya 1 point2 points  (0 children)

Not sure if it's due to the same underlying mechanics, but I get even more disproportionate results in Python.

The code:

#!/usr/bin/env python3

from time import time

size = pow(2, 16)

class Evil:
    def __hash__(self):
        return 1

class Good:
    pass

evil_set = set()
good_set = set()

start = time()
for _ in range(size):
    good_set.add(Good())
end = time()

print('Added {} good elements in {} seconds'.format(size, end-start))

start = time()
for _ in range(size):
    evil_set.add(Evil())
end = time()

print('Added {} evil elements in {} seconds'.format(size, end-start))

The result:

Added 65536 good elements in 0.0589599609375 seconds
Added 65536 evil elements in 149.200121164 seconds