本文整理汇总了Python中time.timer函数的典型用法代码示例。如果您正苦于以下问题:Python timer函数的具体用法?Python timer怎么用?Python timer使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了timer函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: simulator
def simulator():
res_slow = []
res_fast = []
clusters = []
for size in range(2, 201):
clusters.append(gen_random_clusters(size))
# slow
for clist in clusters:
slow_start = timer()
slow(clist)
slow_end = timer()
res_slow.append(slow_end - slow_start)
# fast
for clist in clusters:
fast_start = timer()
fast(clist)
fast_end = timer()
res_fast.append(fast_end - fast_start)
x_axis = [num for num in range(2, 201)]
plt.title('Comparison of efficiency in desktop python environment')
plt.xlabel('size of random clusters')
plt.ylabel('running time (seconds)')
plt.plot(x_axis, res_slow, '-b', label='slow_closest_pair', linewidth=2)
plt.plot(x_axis, res_fast, '-r', label='fast_closest_pair', linewidth=2)
plt.legend(loc='upper left')
plt.show()
示例2: trycontext
def trycontext(n=100000):
while True:
from time import perf_counter as timer
i = iter(range(n))
t1 = timer()
while True:
try:
next(i)
except StopIteration:
break
t2 = timer()
# print("small try", t2 - t1)
i = iter(range(n))
t3 = timer()
try:
while True:
next(i)
except StopIteration:
pass
t4 = timer()
tsmall = D(t2) - D(t1)
tbig = D(t4) - D(t3)
fastest = "Small Try" if tsmall < tbig else "Big Try"
# noinspection PyStringFormat
print("small try %.8f" % tsmall, "big try %.8f" % tbig, "fastest:", fastest,
"%%%.1f" % ((tsmall - tbig) / tsmall * 100))
示例3: main
def main():
start = timer()
# Calling dork_scanner from makman.py for 15 pages and 4 parallel processes
search_result = dork_scanner('intext:Developed by : iNET inurl:photogallery.php', '15', '4')
file_string = '######## By MakMan ########\n'
final_result = []
count = 0
# Running 8 parallel processes for the exploitation
with Pool(8) as p:
final_result.extend(p.map(inject, search_result))
for i in final_result:
if not 'Not Vulnerable' in i and not 'Bad Response' in i:
count += 1
print('------------------------------------------------\n')
print('Url : http:' + i.split(':')[1])
print('User : ' + i.split(':')[2])
print('Version : ' + i.split(':')[3])
print('------------------------------------------------\n')
file_string = file_string + 'http:' + i.split(':')[1] + '\n' + i.split(':')[2] + '\n' + i.split(':')[3] + '\n\n\n'
# Writing vulnerable URLs in a file makman.txt
with open('makman.txt', 'a', encoding='utf-8') as file:
file.write(file_string)
print('Total URLs Scanned : %s' % len(search_result))
print('Vulnerable URLs Found : %s' % count)
print('Script Execution Time : %s' % (timer() - start,))
示例4: main
def main():
# ********************************************************************
# read and test input parameters
# ********************************************************************
print('Parallel Research Kernels version ') #, PRKVERSION
print('Python Dense matrix-matrix multiplication: C = A x B')
if len(sys.argv) != 3:
print('argument count = ', len(sys.argv))
sys.exit("Usage: ./transpose <# iterations> <matrix order>")
iterations = int(sys.argv[1])
if iterations < 1:
sys.exit("ERROR: iterations must be >= 1")
order = int(sys.argv[2])
if order < 1:
sys.exit("ERROR: order must be >= 1")
print('Number of iterations = ', iterations)
print('Matrix order = ', order)
# ********************************************************************
# ** Allocate space for the input and transpose matrix
# ********************************************************************
A = numpy.fromfunction(lambda i,j: j, (order,order), dtype=float)
B = numpy.fromfunction(lambda i,j: j, (order,order), dtype=float)
C = numpy.zeros((order,order))
for k in range(0,iterations+1):
if k<1: t0 = timer()
#C += numpy.matmul(A,B) # requires Numpy 1.10 or later
C += numpy.dot(A,B)
t1 = timer()
dgemm_time = t1 - t0
# ********************************************************************
# ** Analyze and output results.
# ********************************************************************
checksum = numpy.linalg.norm(numpy.reshape(C,order*order),ord=1)
ref_checksum = 0.25*order*order*order*(order-1.0)*(order-1.0)
ref_checksum *= (iterations+1)
epsilon=1.e-8
if abs((checksum - ref_checksum)/ref_checksum) < epsilon:
print('Solution validates')
avgtime = dgemm_time/iterations
nflops = 2.0*order*order*order
print('Rate (MF/s): ',1.e-6*nflops/avgtime, ' Avg time (s): ', avgtime)
else:
print('ERROR: Checksum = ', checksum,', Reference checksum = ', ref_checksum,'\n')
sys.exit("ERROR: solution did not validate")
示例5: main
def main():
print (Style.BRIGHT)
banner()
count = 0
start = timer()
file_string = ''
final_result = []
# Make sure urls.txt is in the same directory
try:
with open( 'urls.txt' ) as f:
search_result = f.read().splitlines()
except:
print( 'urls.txt not found in the current directory. Create your own or download from here. http://makman.tk/vb/urls.txt\n' )
sys.exit(0)
search_result = list( set( search_result ) )
print (' [+] Executing Exploit for ' + Fore.RED + str( len( search_result ) ) + Fore.WHITE + ' Urls.\n')
with Pool(8) as p:
final_result.extend( p.map( inject, search_result ) )
for i in final_result:
if not 'Not Vulnerable' in i and not 'Bad Response' in i:
count += 1
file_string = file_string + i.split( ':::' )[0].strip() + '\n' + i.split( ':::' )[1].strip() + '\n' + i.split( ':::' )[2].strip() + '\n' + i.split( ':::' )[3].strip()
file_string = file_string + '\n------------------------------------------\n'
# Writing Result in a file makman.txt
with open( 'makman.txt', 'a', encoding = 'utf-8' ) as rfile:
rfile.write( file_string )
print( 'Total URLs Scanned : ' + str( len( search_result ) ) )
print( 'Vulnerable URLs Found : ' + str( count ) )
print( 'Script Execution Time : ' + str ( timer() - start ) + ' seconds' )
示例6: main
def main():
banner()
start = timer()
dork = 'inurl:"/component/tags/"'
file_string = '######## By MakMan ########\n'
final_result = []
count = 0
print( '[+] Starting dork scanner for : ' + dork)
sys.stdout.flush()
#Calling dork_scanner from makman.py for 6 pages and 6 parallel processes
search_result = dork_scanner( dork, '6', '6' )
print( '[+] Total URLs found : ' + str( len( search_result ) ) )
with open( 'urls.txt', 'a', encoding = 'utf-8' ) as ufile:
ufile.write( '\n'.join( search_result ) )
print( '[+] URLs written to urls.txt' )
print( '\n[+] Trying Joomla SQL Injection exploit on ' + str( len( search_result ) ) + ' urls' )
sys.stdout.flush()
#Running 8 parallel processes for the exploitation
with Pool(8) as p:
final_result.extend( p.map( inject, search_result ) )
for i in final_result:
if not 'Not Vulnerable' in i and not 'Bad Response' in i:
count += 1
file_string = file_string + i.split('~:')[0] + '\n' + i.split('~:')[1] + '\n' + i.split('~:')[2] + '\n' + i.split('~:')[3] + '\n' + i.split('~:')[4] + '\n' + i.split('~:')[5] + '\n' + i.split('~:')[6] + '\n\n\n'
#Writing vulnerable URLs in a file makman.txt
with open( 'makman.txt', 'a', encoding = 'utf-8' ) as rfile:
rfile.write( file_string )
print( 'Total URLs Scanned : ' + str( len( search_result ) ) )
print( 'Vulnerable URLs Found : ' + str( count ) )
print( 'Script Execution Time : ' + str ( timer() - start ) + ' seconds' )
示例7: test_map
def test_map(times, mock=quick_strptime, repeat=repeat):
t1 = timer()
stripped = map(str.strip, times)
raw = list(takewhile(bool, stripped))
fmt = ParseDateFormat(raw[0])
list(map(mock, raw, repeat(fmt)))
t2 = timer()
return t2 - t1
示例8: do_parse_test
def do_parse_test(times, func=quick_strptime):
t1 = timer()
stripped = map(str.strip, times)
raw = list(takewhile(bool, stripped))
fmt = ParseDateFormat(raw[0])
list(func(date, fmt) for date in raw)
t2 = timer()
return t2 - t1
示例9: _get_fps
def _get_fps(self, frame):
elapsed = int()
start = timer()
preprocessed = self.framework.preprocess(frame)
feed_dict = {self.inp: [preprocessed]}
net_out = self.sess.run(self.out, feed_dict)[0]
processed = self.framework.postprocess(net_out, frame, False)
return timer() - start
示例10: time_test
def time_test(container, key_count, key_range, randrange=randrange, timer=timer):
t1 = timer()
for _i in range(key_count):
keys = test_key % randrange(key_range)
container[keys]
t2 = timer()
return t2 - t1
示例11: test
def test( *args ):
start = timer()
result = [ url for url in sitemap( *args )]
elapsed = timer() - start
print( 'Result: ', end ='' )
for r in result:
print( GET_DUMMY. search( r ). group(), end= ' ' )
print()
print( 'Elapsed:', elapsed * 1000, 'miliseconds' )
示例12: do_superfast_test
def do_superfast_test(times, special_map=special_handler_map):
t1 = timer()
stripped = map(str.strip, times)
raw = list(takewhile(bool, stripped))
fmt = ParseDateFormat(raw[0])
func = special_map[fmt]
list(map(func, raw))
t2 = timer()
return t2 - t1
示例13: main
def main(argv):
# Read Config
starttime = timer()
iniFile = "input/halo_makeDerivs.ini"
Config = ConfigParser.SafeConfigParser()
Config.optionxform = str
Config.read(iniFile)
paramList = []
fparams = {}
cosmo = {}
stepSizes = {}
fparams['hmf_model'] = Config.get('general','hmf_model')
fparams['exp_name'] = Config.get('general','exp_name')
for (key, val) in Config.items('hmf'):
if ',' in val:
param, step = val.split(',')
paramList.append(key)
fparams[key] = float(param)
stepSizes[key] = float(step)
else:
fparams[key] = float(val)
# Make a separate list for cosmology to add to massfunction
for (key, val) in Config.items('cosmo'):
if ',' in val:
param, step = val.split(',')
paramList.append(key)
cosmo[key] = float(param)
stepSizes[key] = float(step)
else:
cosmo[key] = float(val)
fparams['cosmo'] = cosmo
for paramName in paramList:
#Make range for each parameter
#First test: x2 the range, x0.01 the stepsize
if paramName in cosmo:
start = fparams['cosmo'][paramName] - stepSizes[paramName]
end = fparams['cosmo'][paramName] + stepSizes[paramName]
else:
start = fparams[paramName] - stepSizes[paramName]
end = fparams[paramName] + stepSizes[paramName]
width = stepSizes[paramName]*0.01
paramRange = np.arange(start,end+width,width)
for paramVal in paramRange:
if paramName in cosmo:
params = fparams.copy()
params['cosmo'][paramName] = paramVal
else:
params = fparams.copy()
params[paramName] = paramVal
print paramName,paramVal
N = clusterNum(params)
np.savetxt("output/step/"+fparams['exp_name']+'_'+fparams['hmf_model']+"_"+paramName+"_"+str(paramVal)+".csv",N,delimiter=",")
#----------------------------
endtime = timer()
print "Time elapsed: ",endtime-starttime
示例14: timing_middleware
def timing_middleware(next, root, info, **args):
start = timer()
return_value = next(root, info, **args)
duration = timer() - start
logger.debug("{parent_type}.{field_name}: {duration} ms".format(
parent_type=root._meta.name if root and hasattr(root, '_meta') else '',
field_name=info.field_name,
duration=round(duration * 1000, 2)
))
return return_value
示例15: run
def run(cmd, timeout_sec):
start = timer()
with Popen(cmd, shell=True, stdout=PIPE, preexec_fn=os.setsid) as process:
try:
output = process.communicate(timeout=timeout_sec)[0]
except TimeoutExpired:
os.killpg(process.pid, signal.SIGINT) # send signal to the process group
output = process.communicate()[0]
print("DEBUG: process timed out: "+cmd)
print('DEBUG: Elapsed seconds: {:.2f}'.format(timer() - start))