# Performance of list vs. set equality operations

Chris Colbert sccolbert at gmail.com
Tue Apr 6 17:46:49 EDT 2010

```:slaps forehead:

good catch.

On Tue, Apr 6, 2010 at 5:18 PM, Gustavo Narea <me at gustavonarea.net> wrote:
> 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.
> --
> http://mail.python.org/mailman/listinfo/python-list
>

```