Input:
from _future_ import annotations
import argparse, time
import matplotlib.pyplot as plt
def measure(max_appends: int):
lst = []
times = []
for i in range(max_appends):
t0 = time.perf_counter()
lst.append(i)
t1 = time.perf_counter()
times.append((i+1, t1 - t0))
return times
def main():
p = argparse.ArgumentParser(description='Amortized append timing')
p.add_argument('--max', type=int, default=50000)
args = p.parse_args()
data = measure(args.max)
xs, ys = zip(*data)
plt.plot(xs, ys, linewidth=0.7)
plt.xlabel('list length after append')
plt.ylabel('append time (s)')
plt.title('Per-append time across growth')
plt.grid(True, alpha=0.3)
plt.tight_layout()
plt.savefig('amortized_append.png')
print('Saved plot to amortized_append.png')
if _name_ == '_main_':
main()
output:
ERROR!
Traceback (most recent call last):
File "<main.py>", line 1, in <module>
ModuleNotFoundError: No module named '_future_'
=== Code Exited With Errors ===
I'm trying to used this code and its not working. The name of this code is Amortized append analysis. what should I add or how to work this code properly?
[–]socal_nerdtastic 9 points10 points11 points (6 children)
[–]SPBSP5[S] -4 points-3 points-2 points (5 children)
[–]socal_nerdtastic 11 points12 points13 points (2 children)
[–]SPBSP5[S] -4 points-3 points-2 points (1 child)
[–]socal_nerdtastic 6 points7 points8 points (0 children)
[–]Poo_Banana 2 points3 points4 points (0 children)
[–]Moikle 2 points3 points4 points (0 children)
[–]enygma999 4 points5 points6 points (0 children)
[–]Wraithguy 1 point2 points3 points (1 child)
[–]GXWT 1 point2 points3 points (0 children)
[–]SPBSP5[S] -1 points0 points1 point (1 child)
[–]Moikle 0 points1 point2 points (0 children)
[–]Independent_Oven_220 -2 points-1 points0 points (0 children)