matlab - Performance of index creation -
in trying choose indexing method recommend, tried measeure performance. however, measurements confused me lot. ran multiple times in different orders, measurements remain consistent. here how measured performance:
for n = [10000 15000 100000 150000] x = round(rand(n,1)*5)-2; idx1 = x~=0; idx2 = abs(x)>0; tic t = 1:5000 idx1 = x~=0; end toc tic t = 1:5000 idx2 = abs(x)>0; end toc end
and result:
elapsed time 0.203504 seconds. elapsed time 0.230439 seconds. elapsed time 0.319840 seconds. elapsed time 0.352562 seconds. elapsed time 2.118108 seconds. % strange part elapsed time 0.434818 seconds. elapsed time 0.508882 seconds. elapsed time 0.550144 seconds.
i checked , values around 100000 happens, @ 50000 strange measurements occur.
so question is: else experience range, , causes this? (is bug?)
this may due automatic optimization matlab uses basic linear algebra subroutine.
just yours, configuration (osx 10.8.4, r2012a default settings) takes longer compute idx1 = x~=0
x (10e5 elements) x (11e5 elements). see left panel of figure processing time (y-axis) measured different vector size (x-axis). see lower proceesing time n>103000. in panel, displayed number of cores active during calculation. see there no drop one-core configuration. means matlab not optimize execution of ~=
when 1 core active (no parallelization possible). matlab enables optimization routines when 2 conditions met: multiple cores , vector of sufficient size.
the right panel displays results when feature('accel','on'/off')
set off (doc). here, 1 core active (1-core , 4-core identical) , therefore no optimization possible.
finally, function used activating/deactivating cores maxnumcompthreads
. according loren shure, maxnumcompthreads controls both jit , blas. since feature('jit','on'/'off')
did not play role in performance, blas last option remaining.
i leave final sentence loren: "the main message here should not need use function [maxnumcompthreads] @ all! why? because we'd make matlab best job possible you."
accel = {'on';'off'}; figure('color','w'); n = 100000:1000:105000; ind_accel = 2:-1:1 eval(['feature(''accel'',''' accel{ind_accel} ''')']); telapsed = zeros(4,length(n)); ind_core = 1:4 maxnumcompthreads(ind_core); n_core = maxnumcompthreads; ii = 1:length(n) fprintf('core asked: %d(true:%d) - n:%d\n',ind_core,n_core, ii); x = round(rand(n(ii),1)*5)-2; idx1 = x~=0; tstart = tic; t = 1:5000 idx1 = x~=0; end telapsed(ind_core,ii) = toc(tstart); end end h2 = subplot(1,2,ind_accel); plot(n, telapsed,'-o','markersize',10); legend({('1':'4')'}); xlabel('vector size','fontsize',14); ylabel('processing time','fontsize',14); set(gca,'fontsize',14,'ylim',[0.2 0.7]); title(['accel ' accel{ind_accel}]); end
Comments
Post a Comment