Using the Profile class, create a profiler for the whole fib_list function. Replace the dots (...) with your code.
Profiling in Python
Profile class
Report a typo
Write a program in Python 3
import cProfile, pstats, io
# instantiate and enable the profiler
profiler = ...
....enable()
def fib_list(n):
if n < 2:
return n
sequence = [0, 1]
for i in range(2, n + 1):
sequence.append(sequence[i - 1] + sequence[i - 2])
return sequence[n]
fib_list(40)
# disable the profiler
profiler....
# prepare the output statistics
stream = io.StringIO()
stats = pstats.Stats(profiler, stream=stream).sort_stats('cumulative')
stats....
output = ...
___
By continuing, you agree to the JetBrains Academy Terms of Service as well as Hyperskill Terms of Service and Privacy Policy.
Create a free account to access the full topic
By continuing, you agree to the JetBrains Academy Terms of Service as well as Hyperskill Terms of Service and Privacy Policy.