本文整理汇总了Python中timeit.Timer.timeit方法的典型用法代码示例。如果您正苦于以下问题:Python Timer.timeit方法的具体用法?Python Timer.timeit怎么用?Python Timer.timeit使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类timeit.Timer
的用法示例。
在下文中一共展示了Timer.timeit方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
# 需要导入模块: from timeit import Timer [as 别名]
# 或者: from timeit.Timer import timeit [as 别名]
def main():
t = Timer( 'euler14()', "from __main__ import euler14" )
try:
print t.timeit( 1 )
except:
print t.print_exc()
示例2: test_mask_loss_median
# 需要导入模块: from timeit import Timer [as 别名]
# 或者: from timeit.Timer import timeit [as 别名]
def test_mask_loss_median():
th_mask, th_img = T.tensor4(), T.tensor4()
cuda_out = mask_loss_median(th_mask, th_img, impl='cuda')
cuda_mask_loss = theano.function([th_mask, th_img],
[cuda_out['loss'],
cuda_out['median_black'],
cuda_out['loss_per_sample'],
cuda_out['black_white_loss']])
theano_mask_loss = theano.function([th_mask, th_img],
mask_loss_median(th_mask, th_img,
impl='theano')['loss'])
mask_idx = next(masks(1))
image_ok = np.zeros_like(mask_idx)
image_ok[mask_idx > MASK["IGNORE"]] = 1
outs = cuda_mask_loss(mask_idx, image_ok)
for s in outs[1:]:
print(s.shape)
assert (cuda_mask_loss(mask_idx, image_ok)[0] == 0).all()
assert (theano_mask_loss(mask_idx, image_ok) == 0).all()
t = Timer(lambda: cuda_mask_loss(mask_idx, image_ok))
n = 10
print("cuda implementation: {}".format(t.timeit(number=n) / n))
t = Timer(lambda: theano_mask_loss(mask_idx, image_ok))
print("theano implementation: {}".format(t.timeit(number=n) / n))
示例3: compare_times
# 需要导入模块: from timeit import Timer [as 别名]
# 或者: from timeit.Timer import timeit [as 别名]
def compare_times(decorator):
name = decorator.func_name
setup = ("from __main__ import tre_decorator, sum_recursive, sum_iterative"
", _sum_recursive, %s" % name)
t1 = Timer("with tre_decorator(%s):sum_recursive(1000)" % name, setup)
t2 = Timer("with tre_decorator(%s):sum_iterative(1000)" % name, setup)
return (t1.timeit(number=1000), t2.timeit(number=1000))
示例4: main
# 需要导入模块: from timeit import Timer [as 别名]
# 或者: from timeit.Timer import timeit [as 别名]
def main():
global scene
print('Reading \'{}\'...'.format(path))
t = Timer(doImport)
secs = t.timeit(1)
print('> On AssimpCy Took {:0.4f} seconds.'.format(secs))
print('\tHas {} meshes, {} textures, {} materials, {} animations'.format(scene.mNumMeshes,
scene.mNumTextures,
scene.mNumMaterials,
scene.mNumAnimations))
if scene.HasMeshes and scene.mMeshes[0].HasPositions:
print('\tand {} vertices on mesh 0'.format(int(scene.mMeshes[0].mNumVertices)))
v = int(scene.mMeshes[0].mNumVertices / 2)
print('\tVertex {} = {}'.format(v, scene.mMeshes[0].mVertices[v]))
print()
# print(scene.mRootNode.mTransformation)
t = Timer(doImportPy)
secs = t.timeit(1)
print('> On PyAssimp Took {:0.4f} seconds.'.format(secs))
print('\tHas {} meshes, {} textures, {} materials, {} animations'.format(scene.mNumMeshes,
scene.mNumTextures,
scene.mNumMaterials,
scene.mNumAnimations))
if len(scene.meshes) and len(scene.meshes[0].vertices):
print('\tand {} vertices on mesh 0'.format(len(scene.meshes[0].vertices)))
v = int(len(scene.meshes[0].vertices) / 2)
print('\tVertex {} = {}'.format(v, scene.meshes[0].vertices[v]))
# print(scene.rootnode.transformation)
release(scene)
示例5: performance_test
# 需要导入模块: from timeit import Timer [as 别名]
# 或者: from timeit.Timer import timeit [as 别名]
def performance_test():
""" Run test for the given data to test system performance.
(This is used for developing optimisations)
"""
from timeit import Timer
t = Timer("test()", "from __main__ import test")
print t.timeit(number=1)
示例6: test3a_timing_calc
# 需要导入模块: from timeit import Timer [as 别名]
# 或者: from timeit.Timer import timeit [as 别名]
def test3a_timing_calc(self):
"""Test Zernike calculation timing and cache functioning"""
t1 = Timer("""
a=calc_zernike(vec, rad, z_cache)
""", """
from zern import calc_zern_basis, fit_zernike, calc_zernike
import numpy as np
rad = %d
nmodes = %d
vec = np.random.random(nmodes)
z_cache = {}
""" % (self.rad, self.nmodes) )
t2 = Timer("""
a=calc_zernike(vec, rad, {})
""", """
from zern import calc_zern_basis, fit_zernike, calc_zernike
import numpy as np
rad = %d
nmodes = %d
vec = np.random.random(nmodes)
""" % (self.rad, self.nmodes) )
t_cache = t1.timeit(self.calc_iter)/self.calc_iter
t_nocache = t2.timeit(self.calc_iter)/self.calc_iter
# Caching should be at least twice as fast as no caching
# Note that here we do not initialize the cache in the setup, it is
# set to an empty dict which is filled on first run. This test should
# test that this automatic filling works properly
self.assertGreater(t_nocache/2.0, t_cache)
示例7: test_prime_pairs
# 需要导入模块: from timeit import Timer [as 别名]
# 或者: from timeit.Timer import timeit [as 别名]
def test_prime_pairs(times, combi_size):
global t
t = Timer(
"[prime_pairs(combi,%d) for combi in combinations(xrange(100))]" % combi_size,
"from __main__ import prime_pairs; from itertools import combinations",
)
print t.timeit(1)
示例8: parser
# 需要导入模块: from timeit import Timer [as 别名]
# 或者: from timeit.Timer import timeit [as 别名]
def parser(self, path, articles, vocabulary):
doc = fileinput.input(path)
campo_aux = ""
query = None
for line in doc:
i = 0
campo = line[:2]
if (campo == "QN"):
if (query != None):
t = Timer(lambda: query.make_rank(articles, vocabulary))
t = t.timeit(number=1)
self.time = self.time + t
query.metrics(self)
print("Tempo para criar rank e ordenar", t)
query = Query()
line = re.sub("^" + campo, "", line)
query.campos_dic["QN"](line)
continue
if (campo in Query.campos):
campo_aux = str(campo)
line = re.sub("^" + campo, "", line)
query.campos_dic[campo](line)
else:
query.campos_dic[campo_aux](line)
t = Timer(lambda: query.make_rank(articles, vocabulary))
t = t.timeit(number=1)
self.time = self.time + t
query.metrics(self)
print("Tempo para criar rank e ordenar", t)
示例9: bench
# 需要导入模块: from timeit import Timer [as 别名]
# 或者: from timeit.Timer import timeit [as 别名]
def bench(self, width):
def execSilx():
medfilt2d_silx(self.img, width)
def execScipy():
scipy.ndimage.median_filter(input=self.img,
size=width,
mode='nearest')
def execPymca():
medfilt2d_pymca(self.img, width)
execTime = {}
t = Timer(execSilx)
execTime["silx"] = t.timeit(BenchmarkMedianFilter.NB_ITER)
logger.info(
'exec time silx (kernel size = %s) is %s' % (width, execTime["silx"]))
if scipy is not None:
t = Timer(execScipy)
execTime["scipy"] = t.timeit(BenchmarkMedianFilter.NB_ITER)
logger.info(
'exec time scipy (kernel size = %s) is %s' % (width, execTime["scipy"]))
if pymca is not None:
t = Timer(execPymca)
execTime["pymca"] = t.timeit(BenchmarkMedianFilter.NB_ITER)
logger.info(
'exec time pymca (kernel size = %s) is %s' % (width, execTime["pymca"]))
return execTime
示例10: main
# 需要导入模块: from timeit import Timer [as 别名]
# 或者: from timeit.Timer import timeit [as 别名]
def main():
# Listing 3
t1 = Timer(stmt="test1()", setup="from __main__ import test1")
print ("concat ", t1.timeit(number=1000), "milliseconds")
t2 = Timer(stmt="test2()", setup="from __main__ import test2")
print ("concat ", t2.timeit(number=1000), "milliseconds")
t3 = Timer(stmt="test3()", setup="from __main__ import test3")
print ("concat ", t3.timeit(number=1000), "milliseconds")
t4 = Timer(stmt="test4()", setup="from __main__ import test4")
print ("concat ", t4.timeit(number=1000), "milliseconds")
# Listing 4
popzero = timeit.Timer("x.pop(0)", "from __main__ import x")
popend = timeit.Timer("x.pop()", "from __main__ import x")
print "popzero ", popzero.timeit(number=1000)
x = list(range(2000000))
print "popend ", popend.timeit(number=1000)
# Listing 5
print ("pop(0) pop()")
for i in range(1000000,10000001,1000000):
x = list(range(i))
pt = popend.timeit(number=1000)
x = list(range(i))
pz = popzero.timeit(number=1000)
print ("%15.5f, %15.5f" %(pz, pt))
示例11: main2
# 需要导入模块: from timeit import Timer [as 别名]
# 或者: from timeit.Timer import timeit [as 别名]
def main2():
popzero = Timer("x.pop(0)",
"from __main__ import x")
popend = Timer("x.pop()",
"from __main__ import x")
print(popzero.timeit(number=1000))
# 1.5798413809989142
print(popend.timeit(number=1000))
示例12: test_array
# 需要导入模块: from timeit import Timer [as 别名]
# 或者: from timeit.Timer import timeit [as 别名]
def test_array():
from timeit import Timer
m = Timer("arraytest()", "from __main__ import arraytest")
n = Timer("enumeratetest()", "from __main__ import enumeratetest")
print m.timeit() # 5.22479210582
print n.timeit() # 4.34367196717
示例13: main
# 需要导入模块: from timeit import Timer [as 别名]
# 或者: from timeit.Timer import timeit [as 别名]
def main():
parse_command_line()
t = Timer(e1)
results = t.timeit(options.num) / options.num
print 'engine: %0.3f ms per iteration' % (results * 1000)
t = Timer(c1)
results = t.timeit(options.num) / options.num
print 'coroutine: %0.3f ms per iteration' % (results * 1000)
示例14: setUp
# 需要导入模块: from timeit import Timer [as 别名]
# 或者: from timeit.Timer import timeit [as 别名]
def setUp(self):
#print(groffle_faster(mass, density))
self.groffle_slow = groffle_slow(mass, density)
self.groffle_faster = groffle_faster(mass, density)
slowtime = Timer("total = groffle_slow(mass, density)", "from __main__ import groffle_slow, mass, density")
fastertime = Timer("total = groffle_faster(mass, density)", "from __main__ import groffle_faster, mass, density")
self.slowtime = slowtime.timeit(number=1000)
self.fasttime = fastertime.timeit(number=1000)
示例15: compare_ve_conds2
# 需要导入模块: from timeit import Timer [as 别名]
# 或者: from timeit.Timer import timeit [as 别名]
def compare_ve_conds2():
"""Runs a comparison of naive and non-naive variable elimination
when there's conditioning"""
from timeit import Timer
for naive in (True,False):
veti = Timer("asia.copy(True).condition({'Cancer':['absent'],'TbOrCa':['false']}).variable_elimination(['VisitAsia','Tuberculosis', 'XRay','Dyspnea', 'Bronchitis', 'Smoking','TbOrCa'],%s)" % naive,
"from gPy.Examples import asia")
print 'Time taken with naive = %s:' % naive
print veti.timeit(1000)