Skip to content

Instantly share code, notes, and snippets.

@Sinitca-Aleksandr
Last active December 7, 2016 09:59
Show Gist options
  • Save Sinitca-Aleksandr/8c11f169adb5ba4f4e4c3ffd6d7e76d2 to your computer and use it in GitHub Desktop.
Save Sinitca-Aleksandr/8c11f169adb5ba4f4e4c3ffd6d7e76d2 to your computer and use it in GitHub Desktop.
Для автоматизации можно использовать менеджер контекста и с помощью модуля timer.py http://san-tit.blogspot.ru/2016/12/python.html
from timer import Timer
import numpy as np
#Генерация случайных массивов по 1000000 элементов
A = np.random.sample((1000, 1000))
B = np.random.sample((1000, 1000))
with Timer() as t:
C = A*B
print ("Время выполнения: %s s" % t.secs)
import time
class Timer(object):
def __init__(self, verbose=False):
self.verbose = verbose
def __enter__(self):
self.start = time.time()
return self
def __exit__(self, *args):
self.end = time.time()
self.secs = self.end - self.start
self.msecs = self.secs * 1000
if self.verbose:
print ('Время выполения: %f ms' % self.msecs)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment