Michael Ozeryansky
Michael Ozeryansky

Reputation: 8053

Why do Python's set seem to perform worse than arrays

I was testing the performance of "in set" vs "in array". And my tests showed that arrays were faster. Why would that be the case?

Here's my tests and output: https://gist.github.com/mozeryansky/4a0872e9b2ff6e1704d07426ba829ea4

Upvotes: 0

Views: 26

Answers (1)

user2357112
user2357112

Reputation: 280788

You're including the cost of creating the set or list in your timings. (Also, Python calls [1, 2, 3, 4, 5, 6, 7, 8, 9] a list, not an array.)

Upvotes: 1

Related Questions