How can one wrapper time a function across nine input sizes, and why do the seconds it reports say more about your laptop than your algorithm?
Short drills on what this video just taught. Write the code, run the checks, and reveal the answer only if you are stuck.
The timing wrapper is handed a function by name, with no parentheses, because it receives the function itself rather than a call. c_to_f and mysum are already defined for you. Assign the mysum function itself to chosen (do not call it on that line), set label to the name the function reports through __name__, and set result to what chosen gives for an input of 100.
def c_to_f(c):
return c * 9 / 5 + 32
def mysum(n):
total = 0
for i in range(n + 1):
total = total + i
return totalThe time_wrapper(f, L) helper and the list L_N
Record the two parameters, with f passed by name and no parentheses, trace the timing loop line by line, and build L_N from 1 to 100,000,000.
The measured shapes of c_to_f, mysum and square
Write 0 seconds at every input for c_to_f, ten times the input costing ten times the time for mysum, and square at 6 seconds for input 10,000.
One virtue and four failings of timing
State that timing does separate algorithms, then list variation across implementations, computers and languages plus unpredictability at small inputs, with one concrete example for each.