I have a module called preparation.py which verifies the arguments passed to a function, if it isn't present, instead of using a pre-stabilished value as a keyword argument, it searches the argument as an attribute of an object. The code is the following:
def prep(argslist, argsprovided, attributes):
argsout = []
for name in argslist:
if name in argsprovided:
argsout.append(argsprovided[name])
else:
argsout.append(getattr(attributes,name))
return argsout
A simple use of this would be:
import preparation as prep
class example(object):
def __init__(self,x,y):
self.x = x
self.y = y
E = example(1,1)
def foo(**kwargs):
[x,y] = prep.prep(['x','y'],kwargs,E)
return x + y
print( foo())
print( foo(x = 2))
Since almost every function in my code does this check everytime it's called, I want to know if the time spent on it is considerable. The time spent on a single time when this module is called can't be measured using time.time()
method, so I just can't sum a bunch of smaller intervals. Is there a way of doing this?