MATLAB Programming Fundamentals - MathWorks

(やまだぃちぅ) #1

preallocationTest/testIndexingOnLHS 4 0.061333
preallocationTest/testForLoop 4 0.95081


Change Statistical Objectives and Rerun Tests


Change the statistical objectives defined by the runperf function by constructing and
running a time experiment. Construct a time experiment with measurements that reach a
sample mean with an 8% relative margin of error within a 97% confidence level.


Construct an explicit test suite.


suite = testsuite('preallocationTest');


Construct a time experiment with a variable number of sample measurements, and run
the tests.


import matlab.perftest.TimeExperiment
experiment = TimeExperiment.limitingSamplingError('NumWarmups',2,...
'RelativeMarginOfError',0.08, 'ConfidenceLevel', 0.97);
resultsTE = run(experiment,suite);


Running preallocationTest
.......... .......... ....
Done preallocationTest




Compute the statistics for all the test elements.


fullTableTE = vertcat(resultsTE.Samples);
summaryStatsTE = varfun(@mean,fullTableTE,...
'InputVariables','MeasuredTime','GroupingVariables','Name')


summaryStatsTE =


4×3 table


Name GroupCount mean_MeasuredTime




preallocationTest/testOnes 4 0.053506
preallocationTest/testIndexingWithVariable 4 0.19304
preallocationTest/testIndexingOnLHS 4 0.060781


Test Performance Using Scripts or Functions
Free download pdf