Untitled
unknown
python
2 years ago
1.5 kB
27
Indexable
#
# Author: Catherine Leung
# This timer file performs a timing of the functions provided in lab2.py
#
import time
import random
from lab2 import partb_one, partb_two, partb_three
with open("output.csv", "w") as file:
for i in range(1,11):
AMOUNT_OF_DATA = 1000 * i
file.write(str(AMOUNT_OF_DATA)+",")
# generate a list of unique random numbers (AMOUNT_OF_DATA unique values)
my_list = random.sample(range(1, AMOUNT_OF_DATA*10), AMOUNT_OF_DATA)
my_list2 = my_list.copy()
my_list3 = my_list.copy()
total_time = 0
# generate an odd number as the target
target = random.randint(1,AMOUNT_OF_DATA*10-1)
if target % 2 == 0:
target += 1
start_time = time.perf_counter()
result = partb_one(my_list, target)
end_time = time.perf_counter()
total_time = (end_time-start_time)
print(f"time for partb_one()= {total_time}")
file.write(str(total_time)+",")
start_time = time.perf_counter()
result = partb_two(my_list, target)
end_time = time.perf_counter()
total_time = (end_time-start_time)
print(f"time for partb_two()= {total_time}")
file.write(str(total_time)+",")
start_time = time.perf_counter()
result = partb_three(my_list, target)
end_time = time.perf_counter()
total_time = (end_time-start_time)
print(f"time for partb_three()= {total_time}")
file.write(str(total_time)+"\n")
Editor is loading...
Leave a Comment