benchmarking python script reveals mysterious time delays -
i have 2 modules: moduleparent , modulechild
i'm doing in moduleparent:
import modulechild #a bunch of code start = time.time() modulechild.childfunction() finish = time.time() print "calling child function takes:", finish-start, "total seconds" #a bunch of code
i'm doing in modulechild:
def childfunction(): start = time.time() #a bunch of code finish = time.time() print "child function says takes:", finish-start, "total seconds"
the output looks this:
calling child function takes: .24 total seconds child function says takes: 0.0 total seconds
so question is, these .24 seconds coming from?
thank expertise.
#here actual code "childfuntion". shouldn't take .24 seconds.
def getresources(show, resourcename='', resourcetype=''): ''' list of resources given name @show: show name @resourcename: name of resource @resourcetype: type of resource @return: list of resource dictionaries ''' t1 = time.time() cmd = r'c:\tester.exe -cmdfile "c:\%s\info.txt" -user root -pwd root'%show cmd += " -cmd findresources -machineformatted " if resourcename: cmd += '-name %s'%resourcename if resourcetype: cmd += '_' + resourcetype.replace(".", "_") + "_" proc=subprocess.popen(cmd, stdout=subprocess.pipe, stderr=subprocess.pipe) output = proc.stdout.read() output = output.strip() resourcedata = output.split("\r\n") resourcedata = resourcedata[1:] resourcelist = [] data in resourcedata: resourceid, resourcename, resourcetype = data.split("|") rtyp = "_" + resourcetype.replace(".", "_") + "_" shot, assetname = resourcename.split(rtyp) resourcename = assetname path = '//projects/%s/scenes/%s/%s/%s'%(show, shot, resourcetype.replace(".", "/"), assetname) resourcedict = {'id':resourceid, 'name':resourcename, 'type':resourcetype, 'path':path } resourcelist.append(resourcedict) t2 = time.time() print (" ", t2 - t2, "seconds") return resourcelist
edit 2: noticed typo in child function, have t2 - t2 in print statement
ignore below:
calling function has overhead (setting stack space, saving local variables, returning, etc). result suggests function trivial setting function call took longer running code itself.
edit: also, calling timers print ads overhead. think it, calling print account lot of .24 seconds. io slow.
Comments
Post a Comment