MATLAB Programming Fundamentals - MathWorks

(やまだぃちぅ) #1
preallocationTest/testIndexingWithVariable 0.18936 05-Oct-2018 15:02:48 MY-HOSTNAME win64 9.6.0.966561 (R2019a) 590c7818-f956-4019-90fd-472e8ab823e0
preallocationTest/testIndexingWithVariable 0.19051 05-Oct-2018 15:02:49 MY-HOSTNAME win64 9.6.0.966561 (R2019a) 590c7818-f956-4019-90fd-472e8ab823e0
preallocationTest/testIndexingWithVariable 0.20004 05-Oct-2018 15:02:49 MY-HOSTNAME win64 9.6.0.966561 (R2019a) 590c7818-f956-4019-90fd-472e8ab823e0
preallocationTest/testIndexingWithVariable 0.20118 05-Oct-2018 15:02:49 MY-HOSTNAME win64 9.6.0.966561 (R2019a) 590c7818-f956-4019-90fd-472e8ab823e0

Compute Statistics for Single Test Element

Display the mean measured time for the second test. To exclude data collected in the
warm-up runs, use the values in the Samples field.

sampleTimes = results(2).Samples.MeasuredTime;
meanTest2 = mean(sampleTimes)

meanTest2 =

0.1953

The performance testing framework collected 4 sample measurements for the second
test. The test took an average of 0.1953 second.

Compute Statistics for All Test Elements

Determine the average time for all the test elements. The preallocationTest test
includes four different methods for allocating a vector of ones. Compare the time for each
method (test element).

Since the performance testing framework returns a Samples table for each test element,
concatenate all these tables into one table. Then group the rows by test element Name,
and compute the mean MeasuredTime for each group.

fullTable = vertcat(results.Samples);
summaryStats = varfun(@mean,fullTable,...
'InputVariables','MeasuredTime','GroupingVariables','Name')

summaryStats =

4×3 table

Name GroupCount mean_MeasuredTime
__________________________________________ __________ _________________

preallocationTest/testOnes 4 0.056286
preallocationTest/testIndexingWithVariable 4 0.19527

33 Unit Testing

Free download pdf