data transferred in calling a user defined function

此生再无相见时 提交于 2019-12-13 04:34:08

问题


I need to analyze a big source code.Code contains several function calls. Depending upon the computation and communication between function calls, i will need to figure out the best configuration scheme for the overall execution of the source code.

According to me ,

Data communicated in calling a function(if it is on different machine,server etc)=Input Data Size+Output Data Size

for getting the input data size and output data size ,i think i should rewrite all functions to have variable number of inputs and variables outputs.

[varargout] samplefunction(varargin) {

FOR i=0:nargin
 inputdata=inputdata+sizeof(varargin(i));



% Do stuff here


}

isn't there a way to calculate size of cell array(varargin/varargout) directly in Matlab ?

or if u can suggest another approach to measure communicated data between function call ?


回答1:


A call to cellfun() with string inputs would be very fast:

sizes = [cellfun('size',varargin,1); cellfun('size',varargin,2)];

or

lenghts = cellfun('length',varargin);

or

numels  = cellfun('prodofsize',varargin);


来源:https://stackoverflow.com/questions/17055877/data-transferred-in-calling-a-user-defined-function

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!