Created
September 23, 2015 14:10
-
-
Save superbobry/db16053267b778069c9e to your computer and use it in GitHub Desktop.
Вспомогательный модуль для курса "Алгоритмы: теория и практика. Методы"
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import time | |
from matplotlib import pyplot as plt | |
def timed(f, args, *, n_iter=100): | |
acc = float("inf") | |
for i in range(n_iter): | |
t0 = time.perf_counter() | |
f(*args) | |
acc = min(acc, time.perf_counter() - t0) | |
return acc | |
def compare(fs, args): | |
xs = list(range(len(args))) | |
for f in fs: | |
plt.plot(xs, [timed(f, chunk) for chunk in args], | |
label=f.__name__) | |
plt.legend() | |
plt.grid(True) |
Ещё здорово бы в конце функции compare
написать plt.show()
Ещё здорово бы в конце функции
compare
написатьplt.show()
Работает и без него в Jupyter, например. А вот насчет аргументов выше верный комментарий :)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
args, *
в объявлении аргументов похоже на опечатку, да и не работает. Видимо, это нужно исправить на*args