Created
May 3, 2023 11:43
-
-
Save mfleming/71d14dab20f3b05cd85ae2ea7b22dd24 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
#!/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