Computer Science Project
Posted: Fri Nov 22, 2019 9:06 am
I am doing a science fair project about timing math equations on Python. The code I am using is :
import timeit
code_to_test = """
a = range(100000)
b = []
for i in a:
b.append(i*2)
"""
x = 33
y = 999
print(x + y)
elapsed_time = timeit.timeit(code_to_test, number=100)/100
print(elapsed_time)
Will this time the math problems? It says the elapsed time, but I am unaware if that includes the time to do the math problem. Thanks in advance!
import timeit
code_to_test = """
a = range(100000)
b = []
for i in a:
b.append(i*2)
"""
x = 33
y = 999
print(x + y)
elapsed_time = timeit.timeit(code_to_test, number=100)/100
print(elapsed_time)
Will this time the math problems? It says the elapsed time, but I am unaware if that includes the time to do the math problem. Thanks in advance!