本文整理汇总了Python中next.utils.timeit函数的典型用法代码示例。如果您正苦于以下问题:Python timeit函数的具体用法?Python timeit怎么用?Python timeit使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了timeit函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: increment
def increment(self,bucket_id,doc_uid,key,value=1):
"""
increments a key by amount value. If key does not exist, sets {key:value}
Inputs:
(string) bucket_id, (string) doc_uid, (string) key, (int) value
Outputs:
(int) new_value, (bool) didSucceed, (string) message
Usage: ::\n
new_value,didSucceed,message = db.increment(bucket_id,doc_uid,key,value)
"""
try:
if USE_CACHE:
# need to implement cache!!
#############################
new_value,didSucceed,message,dt = utils.timeit(self.permStore.increment)(constants.app_data_database_id,bucket_id,doc_uid,key,value)
self.duration_permStoreSet += dt
if not didSucceed:
return None,False,message
return new_value,True,'Hit PermStore'
else:
new_value,didSucceed,message,dt = utils.timeit(self.permStore.increment)(constants.app_data_database_id,bucket_id,doc_uid,key,value)
self.duration_permStoreSet += dt
if not didSucceed:
return None,False,message
return new_value,True,'Hit PermStore'
except:
return None,False,'DatabaseAPI.increment Failed with unknown exception'
示例2: increment_many
def increment_many(self,bucket_id,doc_uid,key_value_dict):
"""
increments a key by amount value. If key does not exist, sets {key:value}
Inputs:
(string) bucket_id, (string) doc_uid, ({(str)key1:(float)value1,(int)key2:(float) value2}) key_value_dict
Outputs:
(bool) didSucceed, (string) message
Usage: ::\n
didSucceed,message = db.increment_many(bucket_id,doc_uid,key_value_dict)
"""
try:
if USE_CACHE:
# need to implement cache!!
#############################
didSucceed,message,dt = utils.timeit(self.permStore.increment_many)(constants.app_data_database_id,bucket_id,doc_uid,key_value_dict)
self.duration_permStoreSet += dt
if not didSucceed:
return False,message
return True,'Hit PermStore'
else:
didSucceed,message,dt = utils.timeit(self.permStore.increment_many)(constants.app_data_database_id,bucket_id,doc_uid,key_value_dict)
self.duration_permStoreSet += dt
if not didSucceed:
return False,message
return True,'Hit PermStore'
except:
return False,'DatabaseAPI.increment Failed with unknown exception'
示例3: set
def set(self,bucket_id,doc_uid,key,value):
"""
Sets a {key,value} (if already exists, replaces)
Inputs:
(string) bucket_id, (string) doc_uid, (string) key, (string) value
Outputs:
(bool) didSucceed, (string) message
Usage: ::\n
didSucceed,message = db.set(bucket_id,doc_uid,key,value)
"""
try:
if USE_CACHE:
# writes to cache first
didSucceedCache,messageCache,dt = utils.timeit(self.cacheStore.set)(constants.app_data_database_id,bucket_id,doc_uid,key,value)
self.duration_cacheStoreSet += dt
# then writes to permanent store
didSucceedPerm,messagePerm,dt = utils.timeit(self.permStore.set)(constants.app_data_database_id,bucket_id,doc_uid,key,value)
self.duration_permStoreSet += dt
if didSucceedCache and didSucceedPerm:
return True,''
else:
return False,messageCache + '\n' + messagePerm
else:
didSucceedPerm,messagePerm,dt = utils.timeit(self.permStore.set)(constants.app_data_database_id,bucket_id,doc_uid,key,value)
self.duration_permStoreSet += dt
return didSucceedPerm,messagePerm
except:
error = "DatabaseAPI.set Failed with unknown exception"
return False,error
示例4: get_list
def get_list(self,bucket_id,doc_uid,key):
"""
Get a value corresponding to key, returns None if no key exists
Inputs:
(string) bucket_id, (string) doc_uid, (string) key
Outputs:
(list) value, (bool) didSucceed, (string) message
Usage: ::\n
value,didSucceed,message = db.get_list(bucket_id,doc_uid,key)
"""
try:
if USE_CACHE:
# attempts to read file from cache first
keyExistsInCacheStore,didSucceed,message,dt = utils.timeit(self.cacheStore.exists)(constants.app_data_database_id,bucket_id,doc_uid,key)
self.duration_cacheStoreGet += dt
if not didSucceed:
return None,False,'get.cacheStore.exists(key) failed'
if keyExistsInCacheStore:
value,didSucceed,message,dt = utils.timeit(self.cacheStore.get_list)(constants.app_data_database_id,bucket_id,doc_uid,key)
self.duration_cacheStoreGet += dt
if not didSucceed:
return None,False,message
return value,True,'From Cache'
else:
value,didSucceed,message,dt = utils.timeit(self.permStore.get_list)(constants.app_data_database_id,bucket_id,doc_uid,key)
self.duration_permStoreGet += dt
if not didSucceed:
return None,False,message
if value!=None:
didSucceed,message = self.cacheStore.set_list(constants.app_data_database_id,bucket_id,doc_uid,key,value)
if not didSucceed:
return None,False,message
return value,True,'Hit PermStore'
# could not find file
else:
return None,True,'Not in Database'
else:
# not in cache
value,didSucceed,message,dt = utils.timeit(self.permStore.get_list)(constants.app_data_database_id,bucket_id,doc_uid,key)
self.duration_permStoreGet += dt
if not didSucceed:
return None,False,message
return value,True,'Hit PermStore'
except:
return None,False,'DatabaseAPI.get Failed with unknown exception'
示例5: get_list
def get_list(self,key):
"""
retrieve list that was initialized and appeneded to by append_list
"""
value_list,didSucceed,message,dt = utils.timeit(self.db.get_list)(self.bucket_id,self.doc_uid,key)
self.durationGet += dt
return value_list
示例6: get_many
def get_many(self,bucket_id,doc_uid,key_list):
"""
Get values corresponding to keys in key_list, returns None if no key exists
Inputs:
(string) bucket_id, (string) doc_uid, (list of string) key_list
Outputs:
(dict of {key1:value1,key2:value2}) return_dict, (bool) didSucceed, (string) message
Usage: ::\n
return_dict,didSucceed,message = db.get_many(bucket_id,doc_uid,key_list)
"""
try:
if USE_CACHE:
raise
else:
# not using cache
response,dt = utils.timeit(self.permStore.get_many)(constants.app_data_database_id,bucket_id,doc_uid,key_list)
return_dict,didSucceed,message = response
self.duration_permStoreSet += dt
if not didSucceed:
return None,False,message
return return_dict,True,'Hit PermStore'
except:
return None,False,'DatabaseAPI.get Failed with unknown exception'
示例7: get_and_delete
def get_and_delete(self,bucket_id,doc_uid,key):
"""
returns value associated with key and then deltes {key:value}.
If key does not exist, returns None
Inputs:
(string) bucket_id, (string) doc_uid, (string) key
Outputs:
(bool) didSucceed, (string) message
Usage: ::\n
didSucceed,message = db.get_and_delete(bucket_id,doc_uid,key)
"""
try:
if USE_CACHE:
# not implemented
raise
else:
# not using cache
response,dt = utils.timeit(self.permStore.get_and_delete)(constants.app_data_database_id,bucket_id,doc_uid,key)
value,didSucceed,message = response
self.duration_permStoreGet += dt
if not didSucceed:
return None,False,message
return value,True,'Hit PermStore'
except:
return None,False,'DatabaseAPI.get Failed with unknown exception'
示例8: append_list
def append_list(self,key,value):
"""
atomically append a value to a list with key
List is initialized when first value is appended: rc.append_list('answer_pairs',(index,answer))
"""
didSucceed,message,dt = utils.timeit(self.db.append_list)(self.bucket_id,self.doc_uid,key,value)
self.durationSet += dt
return True
示例9: get_many
def get_many(self,key_list):
"""
key_list is a (list) of (string) keys.
get_many returns dictionary with { key:value } for each key in key_list - all values retrieved simultaneously
If requested key does not exist, the key will not exist in the returned dictionary
"""
return_dict,didSucceed,message,dt = utils.timeit(self.db.get_many)(self.bucket_id,self.doc_uid,key_list)
self.durationGet += dt
return return_dict
示例10: wrapper
def wrapper(self, *args, **kwargs):
result, dt = utils.timeit(f)(self, *args, **kwargs)
if op_type == 'set':
self.set_durations += dt
elif op_type == 'get':
self.get_durations += dt
return result
示例11: increment
def increment(self,key,value=1):
"""
Atomic increment. Value can be integer or float.
To initialize 'counter' at value X: rc.increment('counter',X)
Returned value is the value of the key after increment has taken affect
"""
new_value,didSucceed,message,dt = utils.timeit(self.db.increment)(self.bucket_id,self.doc_uid,key,value)
self.durationSet += dt
return new_value
示例12: daemonProcess
def daemonProcess(self,exp_uid,args_json,db,ell):
try:
app_id = self.app_id
log_entry = { 'exp_uid':exp_uid,'task':'daemonProcess','json':args_json,'timestamp':utils.datetimeNow() }
ell.log( app_id+':APP-CALL', log_entry )
# convert args_json to args_dict
try:
args_dict = json.loads(args_json)
except:
error = "%s.daemonProcess input args_json is in improper format" % self.app_id
return '{}',False,error
# check for the fields that must be contained in args or error occurs
necessary_fields = ['alg_uid','daemon_args']
for field in necessary_fields:
try:
args_dict[field]
except KeyError:
error = "%s.daemonProcess input arguments missing field: %s" % (self.app_id,str(field))
return '{}',False,error
alg_daemon_args = args_dict['daemon_args']
alg_uid = args_dict['alg_uid']
alg_id,didSucceed,message = db.get(app_id+':algorithms',alg_uid,'alg_id')
# get sandboxed database for the specific app_id,alg_id,exp_uid - closing off the rest of the database to the algorithm
rc = ResourceClient(app_id,exp_uid,alg_uid,db)
# get specific algorithm to make calls to
alg = utils.get_app_alg(self.app_id,alg_id)
didSucceed,dt = utils.timeit(alg.daemonProcess)(resource=rc,daemon_args_dict=alg_daemon_args)
log_entry = { 'exp_uid':exp_uid,'alg_uid':alg_uid,'task':'daemonProcess','duration':dt,'timestamp':utils.datetimeNow() }
log_entry_durations = { 'exp_uid':exp_uid,'alg_uid':alg_uid,'task':'daemonProcess','duration':dt }
log_entry_durations.update( rc.getDurations() )
meta = {'log_entry_durations':log_entry_durations}
daemon_message = {}
args_out = {'args':daemon_message,'meta':meta}
response_json = json.dumps(args_out)
log_entry = { 'exp_uid':exp_uid,'task':'daemonProcess','json':response_json,'timestamp':utils.datetimeNow() }
ell.log( app_id+':APP-RESPONSE', log_entry )
return response_json,True,''
except Exception, err:
error = traceback.format_exc()
log_entry = { 'exp_uid':exp_uid,'task':'daemonProcess','error':error,'timestamp':utils.datetimeNow() }
ell.log( app_id+':APP-EXCEPTION', log_entry )
return '{}',False,error
示例13: timed_f
def timed_f(*args, **kw):
result, dt = utils.timeit(f)(*args, **kw)
res = None
if get:
self.get_durations += dt
res, didSucceed, message = result
else:
self.set_durations += dt
didSucceed, message = result
return res
示例14: run_alg
def run_alg(self, butler, alg_label, alg, func_name, alg_args):
if 'args' in self.algs_reference_dict[func_name]:
alg_args = verifier.verify(alg_args, self.algs_reference_dict[func_name]['args'])
alg_response, dt = utils.timeit(getattr(alg, func_name))(butler, **alg_args)
alg_response = verifier.verify({'rets':alg_response},
{'rets':self.algs_reference_dict[func_name]['rets']})
log_entry_durations = {'exp_uid':self.exp_uid,
'alg_label':alg_label,
'task':func_name,
'duration':dt}
log_entry_durations.update(butler.algorithms.getDurations())
self.log_entry_durations = log_entry_durations
return alg_response['rets']
示例15: increment_many
def increment_many(self,key_value_dict):
"""
Increments many keys simultaneously.
Example:
increment_many({'Xsum':.65,'T':1})
increment_many({'Xsum':.32,'T':1})
increment_many({'Xsum':.45,'T':1})
data = get_many(['Xsum','T'])
empirical_mean = data['Xsum'] / data['T']
"""
didSucceed,message,dt = utils.timeit(self.db.increment_many)(self.bucket_id,self.doc_uid,key_value_dict)
self.durationSet += dt
return True