Last active
July 2, 2019 04:33
-
-
Save dhilst/2e6f02f4a0eff26581f1a6919330ae35 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
>>> 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