Last active
December 8, 2016 08:41
-
-
Save Sinitca-Aleksandr/31c6f8de94931cf090720615fd49fa9b to your computer and use it in GitHub Desktop.
Сравнение производительности вычислений
This file contains 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
size = 1000 | |
tgen = zeros(1000, 1); | |
tcalc = zeros(1000, 1); | |
for i=1:1000 | |
disp(i); | |
tic; | |
A = rand(size, size); | |
B = rand(size, size); | |
tgen(i) = toc; | |
tic; | |
C = A*B; | |
tcalc(i) = toc; | |
end | |
figure('Name','Calc') | |
plot(tcalc) | |
disp('Среднее время вычисления:'); | |
disp(mean(tcalc)); | |
figure('Name','Gen') | |
plot(tgen) | |
disp('Среднее время генерации:'); | |
disp(mean(tgen)); |
This file contains 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
# -*- coding: utf-8 -*- | |
""" | |
Created on Wed Dec 7 12:53:47 2016 | |
@author: SanTit | |
@url: san-tit.blogspot.com | |
""" | |
from timer import Timer | |
import numpy as np | |
import matplotlib.pyplot as plt | |
tgen = np.zeros(1000); | |
tcalc = np.zeros(1000); | |
for i in range(1000): | |
print(i); | |
with Timer() as t: | |
#Генерация случайных массивов по 1000000 элементов | |
A = np.random.sample((1000, 1000)) | |
B = np.random.sample((1000, 1000)) | |
tgen[i] = t.secs; | |
with Timer() as t: | |
C = np.dot(A,B) | |
tcalc[i] = t.secs; | |
plt.plot(tgen) | |
plt.show() | |
print('Среднее время генерации:' + str(np.mean(tgen))); | |
plt.plot(tcalc) | |
plt.show() | |
print('Среднее время вычисления:' + str(np.mean(tcalc))); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment