inputParser found to be very slow in profiler
Mostrar comentarios más antiguos
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 comentario
David Parks
el 22 de Abr. de 2016
Editada: David Parks
el 22 de Abr. de 2016
Respuestas (1)
Paul Korswagen
el 19 de Dic. de 2018
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 comentarios
Guillaume
el 19 de Dic. de 2018
"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
el 25 de Oct. de 2022
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.
Categorías
Más información sobre Argument Definitions en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!