Created
May 7, 2019 07:13
-
-
Save mhchia/538446d084809dcc0df3dae72d8b1ab6 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
import random | |
from multiaddr.protocols import ( | |
Protocol, | |
PROTOCOLS, | |
P_IP6ZONE, | |
) | |
protocols = tuple(filter(lambda x: x.code != P_IP6ZONE, PROTOCOLS)) | |
def compare_with_is(a: Protocol, b: Protocol) -> bool: | |
return a is b or a == b | |
def compare(a: Protocol, b: Protocol) -> bool: | |
return a == b | |
def test(func_compare): | |
code = random.choice(protocols) | |
for _code in protocols: | |
if func_compare(code, _code): | |
return | |
if __name__ == "__main__": | |
import timeit | |
print(timeit.timeit("test(compare_with_is)", setup="from __main__ import test, compare_with_is")) | |
print(timeit.timeit("test(compare)", setup="from __main__ import test, compare")) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment