目录
Python
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
%matplotlib inline
from matplotlib import pyplot as plt
import time
lst1=[] #记录方法1的运行结果
lst2=[] #记录方法2的运行结
y1=[] #方法1的增长率
y2=[] #方法2的增长率

#对方法1进行测试
for i in [60,100,150,200,280,340,400,500,600,700]:
start = time.clock() #开始计时
coin_charge((1,2,5),i) #i代表每次需要兑换的钱数
lst1.append(time.clock()-start) #记录每一组数据的运行时间

#对方法2进行测试
for i in [60,100,150,200,280,340,400,500,600,700]:
start = time.clock()#开始计时
coin_charge_cache((1,2,5),i) #i代表每次需要兑换的钱数
lst2.append(time.clock()-start)#记录每一组数据的运行时间
#计算增长率
y1.append(lst1[0])
y2.append(lst2[0])
x=[60,100,150,200,280,340,400,500,600,700]
x1=[0]
#计算时间和数据的增长率
for i in range(1,len(lst1)):
y1.append(lst1[i]/lst1[0])
y2.append(lst2[i]/lst2[0])
x1.append(x[i]/x[0])

print(x1)
print(y1)
print(y2)
#画图
plt.plot(x1,y1,label="coin_charge")
plt.plot(x1,y2,label="coin_charge_cache")
plt.title("Example")
plt.xlabel("N-Growth")
plt.ylabel("Time-Growth")
plt.legend()
plt.show()






from graphviz import Digraph
dot = Digraph()
dot.format = 'svg'
dot.graph_attr['bgcolor']='transparent'

dot.node_attr={'color':'gray80','fontcolor':'black','style':'rounded','shape':'record'}
dot.edge_attr={'color':'gray60','fontcolor':'gra60','fontcolor':'brown1'}
dot.attr('node')
dot.node('A','{Sum_find([1,2],3)|2}')
dot.node('B','{Sum_find([2],3)|0}')
dot.node('C','{Sum_find([1,2],2)|2}')
dot.node('B1','{Sum_find([],3)|0}')
dot.node('B2','{Sum_find([2],1)|0}')
dot.node('B21','{Sum_find([],1)|0}')
dot.node('C1','{Sum_find([2],2)|1}')
dot.node('C2','{Sum_find([1,2],1)|1}')
dot.node('C11','{Sum_find([0],2)|0}')
dot.node('C12','{Sum_find([2],0)|1}')
dot.node('C21','{Sum_find([2],1)|0}')
dot.node('C22','{Sum_find([1,2],0)|1}')
dot.node('C211','{Sum_find([],1)|0}')
dot.edge('A','B')
dot.edge('A','C')
dot.edge('B','B1')
dot.edge('B','B2')
dot.edge('C','C1')
dot.edge('C','C2')
dot.edge('B2','B21')
dot.edge('C1','C11')
dot.edge('C1','C12')
dot.edge('C2','C21')
dot.edge('C2','C22')
dot.edge('C21','C211')
dot.render('D:index11')
dot
文章作者: Danqing
文章链接: http://yoursite.com/2019/12/29/python/
版权声明: 本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来自 DanqingBlog
打赏
  • 微信
  • 支付宝

评论