-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTesting_lib_functionality.py
More file actions
87 lines (67 loc) · 9.89 KB
/
Testing_lib_functionality.py
File metadata and controls
87 lines (67 loc) · 9.89 KB
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
83
84
85
86
87
from BigNum import * # Работаем с файлом/классом как с импортированной библиотекой.
import time
import matplotlib.pyplot as plt
import numpy as np
from scipy.interpolate import interp1d
def main():
bignumA = BigNum.input('Введите число А: ')
bignumB = BigNum.input('Введите число В: ')
print('B - A = ', bignumB - bignumA)
print('A - B = ', bignumA - bignumB)
print('A + B = ', bignumA + bignumB)
karatsuba = bignumA * bignumB
print('A * B = ', karatsuba, 'Количество разрядов:', len(karatsuba._to_string()))
#print('A / B = ', bignumA / bignumB)
print('max(A, B) : ', bignumA.max(bignumB))
# Протестируем имплементированный метод умножения Карацубы.
print('Тестируем библиотеку на скорость выполнения операций:')
bignumA = BigNum('98765432198765432198765432198765432198765432198765432198765432198765432198765432198765432198765432198765432198765432198765434321987654321987654343219876543219876543432198765432198765432198765432198765432198765432198765432198765432198765432198764321987654321987654321987643219876543212') #987654321987643219876
bignumB = BigNum('12345678912345678912345678912345578912345678912345678912345678912345678912345678912345678912345678912345678912345678912345676789123456789123456767891234567891234567678912345678912345678912345678912345678912345678912345678912345678912345678912345678912345678912345678912345678912345678') #891234567891234567891
print(len(bignumA._to_string()), len(bignumB._to_string()))
print('Base:', BASE, len(str(BASE-1)), '\nA * B = ', end='')
start_time = time.time()
print(bignumA * bignumB)
print("Операция заняла %.5f секунд" % (time.time() - start_time))
x = np.linspace(0, 10)
base_10 = "0.003989219665527344 0.005980014801025391 0.00600981712341308594 0.00797724723815917969 0.00797867774963378906 0.00897741317749023438 0.00994348526000976562 0.01395368576049804688 0.01396203041076660156 0.01764631271362304688 0.01795339584350585938 0.02094388008117675781 0.02150511741638183594 0.02695107460021972656 0.02794909477233886719 0.03390884399414062500 0.04687786102294921875 0.05884218215942382812 0.06482744216918945312 0.07281541824340820312 0.08178043365478515625 0.09474635124206542969 0.09975719451904296875 0.14520454406738281250 0.18253731727600097656 0.19248533248901367188 0.21897554397583007812 0.25753068923950195312 0.27825689315795898438 0.36863279342651367188 0.67331433296203613281 0.60656309127807617188 0.69098377227783203125 0.81800937652587890625 1.00137186050415039062 1.66702699661254882812 1.50021910667419433594 1.58478212356567382812 1.63713765144348144531"
base_10 = base_10.replace('\t', ' ').split(' ')
base_10 = [float(item) for item in base_10]
base_100 = "0.0009987354278564453 0.00299167633056640625 0.00299167633056640625 0.00299572944641113281 0.00299191474914550781 0.00398874282836914062 0.00398898124694824219 0.00401520729064941406 0.00498628616333007812 0.00797820091247558594 0.00797843933105468750 0.00797867774963378906 0.00899362564086914062 0.00997328758239746094 0.01052904129028320312 0.01296520233154296875 0.01797676086425781250 0.02493333816528320312 0.02590656280517578125 0.03188371658325195312 0.03689551353454589844 0.04188585281372070312 0.04188799858093261719 0.05984258651733398438 0.07380533218383789062 0.08027458190917968750 0.09175443649291992188 0.10673713684082031250 0.12067723274230957031 0.17025113105773925781 0.22740197181701660156 0.26428747177124023438 0.30116939544677734375 0.36158561706542968750 0.39636945724487304688 0.51544189453125000000 0.65038824081420898438 1.00101041793823242188 0.68170452117919921875"
base_100 = base_100.replace('\t', ' ').split(' ')
base_100 = [float(item) for item in base_100]
base_1000 = "0.0009970664978027344 0.00099658966064453125 0.00099921226501464844 0.00099754333496093750 0.00099730491638183594 0.00299215316772460938 0.00298190116882324219 0.00299263000488281250 0.00299119949340820312 0.00398945808410644531 0.00398516654968261719 0.00398921966552734375 0.00398921966552734375 0.00398921966552734375 0.00501084327697753906 0.00899839401245117188 0.01096343994140625000 0.01199650764465332031 0.01498484611511230469 0.01493716239929199219 0.01994562149047851562 0.02893328666687011719 0.02792525291442871094 0.03094244003295898438 0.03989219665527343750 0.04791021347045898438 0.05385899543762207031 0.06981086730957031250 0.08479881286621093750 0.10070228576660156250 0.12865591049194335938 0.13266921043395996094 0.18964552879333496094 0.25888442993164062500 0.26059651374816894531 0.30636763572692871094 0.33451938629150390625 0.34806847572326660156 0.40591430664062500000"
base_1000 = base_1000.replace('\t', ' ').split(' ')
base_1000 = [float(item) for item in base_1000]
base_10000 = "0.00099730491638183594 0.00099730491638183594 0.00099730491638183594 0.00099706649780273438 0.00099730491638183594 0.00099730491638183594 0.00099730491638183594 0.00102519989013671875 0.00102162361145019531 0.00301718711853027344 0.00299191474914550781 0.00398659706115722656 0.00398921966552734375 0.00401377677917480469 0.00399446487426757812 0.00695967674255371094 0.00700712203979492188 0.00999784469604492188 0.01097083091735839844 0.01296567916870117188 0.01397252082824707031 0.01795220375061035156 0.01897716522216796875 0.02196836471557617188 0.03091740608215332031 0.03191447257995605469 0.04089307785034179688 0.04291081428527832031 0.05485439300537109375 0.07382798194885253906 0.09529542922973632812 0.12070155143737792969 0.12765812873840332031 0.16655445098876953125 0.16654682159423828125 0.23143267631530761719 0.28274893760681152344 0.29702186584472656250 0.29930710792541503906"
base_10000 = base_10000.replace('\t', ' ').split(' ')
base_10000 = [float(item) for item in base_10000]
base_100000 = "0.00099778175354003906 0.00099754333496093750 0.00099754333496093750 0.00099754333496093750 0.00099730491638183594 0.00099730491638183594 0.00099802017211914062 0.00099802017211914062 0.00099802017211914062 0.00099778175354003906 0.00099921226501464844 0.00099945068359375000 0.00199341773986816406 0.00396418571472167969 0.00398898124694824219 0.00452852249145507812 0.00498676300048828125 0.00498652458190917969 0.00698065757751464844 0.01097011566162109375 0.01197719573974609375 0.01398682594299316406 0.01396179199218750000 0.01795172691345214844 0.01897358894348144531 0.02493309974670410156 0.03587913513183593750 0.03690028190612792969 0.04288554191589355469 0.05584621429443359375 0.07380223274230957031 0.10773658752441406250 0.11919021606445312500 0.13064074516296386719 0.14192748069763183594 0.16556239128112792969 0.17569303512573242188 0.21936750411987304688 0.24135231971740722656"
base_100000 = base_100000.replace('\t', ' ').split(' ')
base_100000 = [float(item) for item in base_100000]
base_1000000 = "0.00099825859069824219 0.00099873542785644531 0.00099730491638183594 0.00099682807922363281 0.00099730491638183594 0.00099730491638183594 0.00099396705627441406 0.00099730491638183594 0.00099730491638183594 0.00099730491638183594 0.00099754333496093750 0.00102210044860839844 0.00102210044860839844 0.00099706649780273438 0.00199675559997558594 0.00401425361633300781 0.00498795509338378906 0.00496220588684082031 0.00498676300048828125 0.00501394271850585938 0.00795292854309082031 0.01298928260803222656 0.01299166679382324219 0.01495695114135742188 0.01695394515991210938 0.02194118499755859375 0.02094364166259765625 0.02792668342590332031 0.04091501235961914062 0.04586863517761230469 0.05784630775451660156 0.06283235549926757812 0.08078169822692871094 0.17755031585693359375 0.12668561935424804688 0.13862919807434082031 0.14034962654113769531 0.15957307815551757812 0.19569253921508789062"
base_1000000 = base_1000000.replace('\t', ' ').split(' ')
base_1000000 = [float(item) for item in base_1000000]
base_10000000 = "0.00099420547485351562 0.00099778175354003906 0.00099778175354003906 0.00099754333496093750 0.00099730491638183594 0.00099730491638183594 0.00099778175354003906 0.00099682807922363281 0.00099802017211914062 0.00099730491638183594 0.00099754333496093750 0.00099849700927734375 0.00099849700927734375 0.00099754333496093750 0.00202155113220214844 0.00199389457702636719 0.00536179542541503906 0.00498700141906738281 0.00600671768188476562 0.00598311424255371094 0.00698375701904296875 0.00698375701904296875 0.00900149345397949219 0.01396226882934570312 0.01695442199707031250 0.01695656776428222656 0.02194142341613769531 0.02396607398986816406 0.02595496177673339844 0.04487943649291992188 0.05436921119689941406 0.05482840538024902344 0.07008004188537597656 0.08776378631591796875 0.11172580718994140625 0.15957617759704589844 0.14059758186340332031 0.15579342842102050781 0.14663434028625488281"
base_10000000 = base_10000000.replace('\t', ' ').split(' ')
base_10000000 = [float(item) for item in base_10000000]
x = "8,9,10,11,12,13,14,15,16,17,18,19,20,23,24,28,32,36,40,44,48,52,56,64,72,80,88,96,104,124,144,164,184,204,224,244,264,284,304"
x = x.split(',')
x = [int(item) for item in x]
with plt.style.context('seaborn-bright'): #bmh
plt.plot(x, base_10, label='10')
#plt.xticks(x)
#plt.yticks(base_10)
plt.plot(x, base_100, label='100')
plt.plot(x, base_1000, label='1 000')
plt.plot(x, base_10000, label='10 000')
plt.plot(x, base_100000, label='100 000')
plt.plot(x, base_1000000, label='1 000 000')
plt.plot(x, base_10000000, label='10 000 000')
plt.legend(bbox_to_anchor=(.15, .9), loc='upper left', borderaxespad=-4.9)
# Number of accent colors in the color scheme
plt.title('Умножение Карацубы')
plt.xlabel('Количество цифр', fontsize=14)
plt.ylabel('Время, с', fontsize=14)
plt.show()
if __name__ == '__main__':
main()