-
Notifications
You must be signed in to change notification settings - Fork 30
Expand file tree
/
Copy pathutils.py
More file actions
32 lines (28 loc) · 966 Bytes
/
utils.py
File metadata and controls
32 lines (28 loc) · 966 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import time
import matplotlib.pyplot as plt
import random
def createData(sizes=[]):
"""
生成指定数量的测试数据
:param sizes: 数据规模大小列表
:return: 生成的点列表
"""
datasets = []
for size in sizes:
data = [random.randint(1, 100000) for _ in range(size)]
datasets.append(data)
return datasets
def run_algorithm(algorithm, data): #测试算法运行时间
start_time = time.time()
algorithm(data)
end_time = time.time()
return (end_time - start_time) * 1000
def plot_performance_curve(algorithm, data_sets):
sizes = [len(data) for data in data_sets]
times = [run_algorithm(algorithm, data) for data in data_sets]
plt.plot(sizes, times, '-o')
plt.xlabel("Data Size")
plt.ylabel("Running Time (ms)")
plt.title("Performance Curve for {}".format(algorithm.__name__))
plt.savefig("Performance_Curve_for_{}".format(algorithm.__name__))
plt.show()