Back to the main page.
Bug 2225 - speed up warning_once
Status | CLOSED FIXED |
Reported | 2013-07-30 16:07:00 +0200 |
Modified | 2015-01-12 09:24:05 +0100 |
Product: | FieldTrip |
Component: | core |
Version: | unspecified |
Hardware: | PC |
Operating System: | Mac OS |
Importance: | P4 normal |
Assigned to: | Jan-Mathijs Schoffelen |
URL: | |
Tags: | |
Depends on: | |
Blocks: | |
See also: |
Robert Oostenveld - 2013-07-30 16:07:27 +0200
Arjen and I noticed that dipole fitting was very slow due to (in the iterative loop) warning_once being called. This caused strcmp to be called many times, which made it very slow. I guess it should be possible to speed it up.
Jörn M. Horschig - 2013-07-31 08:26:02 +0200
hm, in your case, strcmp is called only once per function call (to check whether it is a '-clear' call). I am not aware of any tweaks for that :/
Robert Oostenveld - 2013-07-31 09:01:40 +0200
once per function call can still be very often if the parent function is called in a loop. e.g. consider ---- function test_bug2225 for i=1:1000 issue_warning end % for end % main function function issue_warning warning_once('this warning should not show too often'); end % subfunction ----- assuming something useful is done inside "issue_warning", then the warning handling should not add too much to the execution time.
Jörn M. Horschig - 2013-07-31 09:18:32 +0200
I really wouldn't worry too much about strcmp s = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'; %find number of random characters to choose from numRands = length(s); %specify length of random string to generate sLength = 50; %generate random string randString = s( round(rand(1,sLength)*numRands) ); tic; for i=1:10000 randString = s( ceil(rand(1,sLength)*numRands) ); if strcmp(randString, '-clear') fprintf('huiii'); end end toc Elapsed time is 0.052663 seconds. After profiling, it seems rather that getsubfield and strtok (as part of the *subfield functions) are taking ~80% of the time
Robert Oostenveld - 2013-07-31 12:42:30 +0200
(In reply to comment #3) > it seems rather that getsubfield and strtok (as part of the > *subfield functions) are taking ~80% of the time So that means that the function can in principle be made 5x faster, i.e. 10ms rather than 50ms per call.