Skip to content

Instantly share code, notes, and snippets.

@mfleming
Created May 3, 2023 11:43
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 mfleming/71d14dab20f3b05cd85ae2ea7b22dd24 to your computer and use it in GitHub Desktop.
Save mfleming/71d14dab20f3b05cd85ae2ea7b22dd24 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python3
#
# Build three lists of integers with NUM_ELEMS elements where each element is a random integer in
# the range [0,9223372036854775807]. Then measure the time to iterate over all three lists in a
# O(n^3) loop.
import random
import sys
import time
NUM_ELEMS = 5000
def main():
list1 = random.sample(range(0,sys.maxsize),NUM_ELEMS)
list2 = random.sample(range(0,sys.maxsize),NUM_ELEMS)
list3 = random.sample(range(0,sys.maxsize),NUM_ELEMS)
start = time.time()
for l1 in list1:
for l2 in list2:
for l3 in list3:
pass
print(time.time() - start)
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment