Построение графиков
This commit is contained in:
parent
07dc80bee2
commit
e741fab112
|
|
@ -159,4 +159,61 @@ def run_test(data, struct_name, create, insert, find, delete):
|
|||
delete(s, name)
|
||||
times['delete'].append(time.perf_counter() - start)
|
||||
|
||||
return {op: sum(t)/len(t) for op, t in times.items()}
|
||||
return {op: sum(t)/len(t) for op, t in times.items()}
|
||||
def plot_results(data_matrix):
|
||||
structures = ['LinkedList', 'HashTable', 'BST']
|
||||
operations = ['insert', 'search', 'delete']
|
||||
modes = ['random', 'sorted']
|
||||
|
||||
fig, axes = plt.subplots(2, 2, figsize=(14, 12))
|
||||
|
||||
x = np.arange(len(structures))
|
||||
width = 0.25
|
||||
|
||||
for i, op in enumerate(operations):
|
||||
values = [data_matrix[s]['random'][op] for s in structures]
|
||||
axes[0,0].bar(x + i*width, values, width, label=op)
|
||||
axes[0,0].set_xlabel('Структура данных')
|
||||
axes[0,0].set_ylabel('Время (секунды)')
|
||||
axes[0,0].set_title('Случайный порядок данных')
|
||||
axes[0,0].set_xticks(x + width, structures)
|
||||
axes[0,0].legend()
|
||||
axes[0,0].grid(True, alpha=0.3)
|
||||
|
||||
for i, op in enumerate(operations):
|
||||
values = [data_matrix[s]['sorted'][op] for s in structures]
|
||||
axes[0,1].bar(x + i*width, values, width, label=op)
|
||||
axes[0,1].set_xlabel('Структура данных')
|
||||
axes[0,1].set_ylabel('Время (секунды)')
|
||||
axes[0,1].set_title('Отсортированный порядок данных')
|
||||
axes[0,1].set_xticks(x + width, structures)
|
||||
axes[0,1].legend()
|
||||
axes[0,1].grid(True, alpha=0.3)
|
||||
|
||||
x = np.arange(len(operations))
|
||||
width = 0.35
|
||||
for i, mode in enumerate(modes):
|
||||
values = [data_matrix['BST'][mode][op] for op in operations]
|
||||
axes[1,0].bar(x + i*width, values, width, label=mode)
|
||||
axes[1,0].set_xlabel('Операция')
|
||||
axes[1,0].set_ylabel('Время (секунды)')
|
||||
axes[1,0].set_title('BST: влияние порядка данных')
|
||||
axes[1,0].set_xticks(x + width/2, operations)
|
||||
axes[1,0].legend()
|
||||
axes[1,0].grid(True, alpha=0.3)
|
||||
|
||||
for struct in structures:
|
||||
times_random = [data_matrix[struct]['random'][op] for op in operations]
|
||||
times_sorted = [data_matrix[struct]['sorted'][op] for op in operations]
|
||||
axes[1,1].plot(operations, times_random, marker='o', label=f'{struct} случайный')
|
||||
axes[1,1].plot(operations, times_sorted, marker='s', linestyle='--', label=f'{struct} отсортированный')
|
||||
axes[1,1].set_yscale('log')
|
||||
axes[1,1].set_xlabel('Операция')
|
||||
axes[1,1].set_ylabel('Время (секунды) - логарифмическая шкала')
|
||||
axes[1,1].set_title('Сравнение производительности')
|
||||
axes[1,1].legend()
|
||||
axes[1,1].grid(True, alpha=0.3)
|
||||
|
||||
plt.tight_layout()
|
||||
plt.savefig('performance_graphs.png')
|
||||
plt.show()
|
||||
Loading…
Reference in New Issue
Block a user