inputParser found to be very slow in profiler
이전 댓글 표시
I'm using inputParser. In a profiling session I discovered something disturbing, inputParser is costing more time than even large matrix operations (where cpu time should be).
Just the setup of inputPaser cost 0.5s on 3000 function calls.
p = inputParser
To give a scale comparison, running bsxfun to add arrays to medium size matrices later in the same function took 0.36s on 6000 calls. In what world can instantiating the inputParser be more than twice as costly as a non-trivial matrix operation?
Worse by far is parse:
parse( p, required_struct_with_large_matrices, required_large_matrix, varargin(:) )
2.33s on 3000 calls to parse. That was more time-expensive than a medium/large matrix-matrix multiplication later in the code. Yikes!
I don't see any threads discussing this elsewhere. Anyone have an idea what might be going on here? Is inputParser really the disaster it appears to be? Or are there quirks I don't know about yet?
If I remove the 2 required variables, the struct and large matrix, and just process 1 single optional parameter (a string with 2 possible options with a validation of `@(v)any(strcmp(PREDICT_MODE,v))`) the time cost drops from 2.33s down to 1s. A big improvement, but still completely horrible, and more costly than non-trivial matrix operations later in the code.
댓글 수: 1
David Parks
2016년 4월 22일
편집: David Parks
2016년 4월 22일
답변 (1개)
Paul Korswagen
2018년 12월 19일
You should not run the large matrices through inputParser.
function example(largematrix,varargin)
a = inputParser;
%Required:
addRequired(a,'LargeMatrix');
%Parameter:
addParameter(a,'NV1',0);
parse(a,1,varargin{:}); %note the placeholder for the LargeMatrix
end
댓글 수: 2
Guillaume
2018년 12월 19일
"You should not run the large matrices through inputParser".
Have you got any explanation to support that statement? Passing a matrix, regardless of its size to a function should be instantaneous as long as the matrix is not modified. It's just one shared pointer copy.
Ryan
2022년 10월 25일
I ran into this same issue. When I used placeholders like stated above, the time went from ~53 seconds to ~0.0003 seconds. I'm not sure why this happens though.
카테고리
도움말 센터 및 File Exchange에서 Argument Definitions에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!