Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
>>> from dis import dis
>>> dis('"foo" in {"bar", "tar"}')
1 0 LOAD_CONST 0 ('foo')
2 LOAD_CONST 1 (frozenset({'bar', 'tar'}))
4 COMPARE_OP 6 (in)
6 RETURN_VALUE
>>> dis('"foo" == "bar" or "foo" == "tar"')
1 0 LOAD_CONST 0 ('foo')
2 LOAD_CONST 1 ('bar')
4 COMPARE_OP 2 (==)
6 JUMP_IF_TRUE_OR_POP 14
8 LOAD_CONST 0 ('foo')
10 LOAD_CONST 2 ('tar')
12 COMPARE_OP 2 (==)
>> 14 RETURN_VALUE
>>>
>>> from timeit import timeit
>>> timeit('"foo" in {"bar", "tar"}')
0.026380221999716014
>>> timeit('"foo" == "bar" or "foo" == "tar"')
0.061998130004212726
>>>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.