调用用户定义函数时传输的数据 [英] data transferred in calling a user defined function
问题描述
我需要分析一个大的源代码.代码包含几个函数调用. 根据函数调用之间的计算和通信,我将需要为整体执行源代码找出最佳的配置方案.
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.
据我说,
在调用函数时通信的数据(如果它在不同的机器,服务器等上)=输入数据大小+输出数据大小
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
}
没有一种方法可以直接在Matlab中计算单元格数组的大小(varargin/varargout)吗?
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 ?
推荐答案
对 cellfun()
使用字符串输入会非常快:
A call to cellfun()
with string inputs would be very fast:
sizes = [cellfun('size',varargin,1); cellfun('size',varargin,2)];
或
lenghts = cellfun('length',varargin);
或
numels = cellfun('prodofsize',varargin);
这篇关于调用用户定义函数时传输的数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!