Performance of list vs. set equality operations

Gustavo Narea me at gustavonarea.net
Tue Apr 6 23:18:38 CEST 2010


On Apr 6, 7:28 pm, Chris Colbert <sccolb... at gmail.com> wrote:
> the proof is in the pudding:
>
> In [1]: a = range(10000)
>
> In [2]: s = set(a)
>
> In [3]: s2 = set(a)
>
> In [5]: b = range(10000)
>
> In [6]: a == b
> Out[6]: True
>
> In [7]: s == s2
> Out[7]: True
>
> In [8]: %timeit a == b
> 1000 loops, best of 3: 204 us per loop
>
> In [9]: %timeit s == s2
> 10000 loops, best of 3: 124 us per loop


I think you meant to set "s2 = set(b)":
=====
In [1]: a = range(10000)

In [2]: b = range(10000)

In [3]: s1 = set(a)

In [4]: s2 = set(a)

In [5]: s3 = set(b)

In [6]: %timeit a == b
10000 loops, best of 3: 191 us per loop

In [7]: %timeit s1 == s2
10000 loops, best of 3: 118 us per loop

In [8]: %timeit s1 == s3
1000 loops, best of 3: 325 us per loop
=====

Cheers.



More information about the Python-list mailing list