Skip to content

Instantly share code, notes, and snippets.

@mhchia
Created May 7, 2019 07:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mhchia/538446d084809dcc0df3dae72d8b1ab6 to your computer and use it in GitHub Desktop.
Save mhchia/538446d084809dcc0df3dae72d8b1ab6 to your computer and use it in GitHub Desktop.
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