Skip to content

Instantly share code, notes, and snippets.

@halfak
Created September 8, 2020 13:52
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 halfak/f6e18823eaf1a40fd0868ff17a2a0688 to your computer and use it in GitHub Desktop.
Save halfak/f6e18823eaf1a40fd0868ff17a2a0688 to your computer and use it in GitHub Desktop.
$ python
Python 3.8.2 (default, Jul 16 2020, 14:00:26)
[GCC 9.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import time
>>> commons_pids = list(range(1, 50))
>>> entity_pids = list(range(50, 100))
>>> def linear_scan():
... for val in entity_pids:
... if val in commons_pids:
... return True
...
>>> entity_pids_set = set(entity_pids)
>>> commons_pids_set = set(commons_pids)
>>> def set_scan():
... return len(entity_pids_set & commons_pids_set) > 0
...
>>> start = time.time(); len([set_scan() for i in range(1000)]); print(time.time() - start)
1000
0.0016851425170898438
>>> start = time.time(); len([linear_scan() for i in range(1000)]); print(time.time() - start)
1000
0.030255556106567383
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment