[docs]classBaseExecutor(ABC):"""A base class for a benchmark executor """def__init__(self,**kwargs):return
[docs]defexecute(self,func,args,**kwargs):"""Executes a given function over a list or dict of arguments, and passes arbitrary keyword arguments to the function. The particular meaning of "execution" is defined in ``_execute()`` method, and implemented in inherited executor classes. Parameters ---------- func : callable The function to be executed. args : list | dict A list (or dict) of input arguments for ``func``. kwargs : dict, optional Arbitrary keyword arguments passed to ``func``. Returns ------- results: list | dict Results of the execution in the same format as input arguments. """is_list=isinstance(args,list)is_dict=isinstance(args,dict)ifnot(is_listoris_dict):raiseValueError("Unsupported 'args' type. Use either list or dict.")ifis_dict:keys,args=zip(*args.items())results=self._execute(func,args,**kwargs)ifis_dict:results=dict(zip(keys,results))returnresults
[docs]@abstractmethoddef_execute(self,func,args,**kwargs):"""Executor-specific implementation (see inherited classes) :meta public: """return