Main Content

run

Class: matlab.perftest.TimeExperiment
Namespace: matlab.perftest

Run time experiment on test suite

Description

results = run(experiment,suite) runs a time experiment on a test suite, and returns an array of TimeResult objects. Each element in results corresponds to an element in suite.

example

Input Arguments

expand all

Experiment to collect measurements on, specified as a matlab.perftest.TimeExperiment instance.

Suite of tests, specified as a matlab.unittest.Test array.

Examples

expand all

In your current working folder, create a class-based test, preallocationTest.m, that compares different methods of preallocation.

classdef preallocationTest < matlab.perftest.TestCase
    methods (Test)
        function testOnes(testCase)
            x = ones(1,1e7);
        end

        function testIndexingWithVariable(testCase)
            id = 1:1e7;
            x(id) = 1;
        end

        function testIndexingOnLHS(testCase)
            x(1:1e7) = 1;
        end

        function testForLoop(testCase)
            for i = 1:1e7
                x(i) = 1;
            end
        end
    end
end

Create a test suite.

suite = testsuite('preallocationTest');

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

import matlab.perftest.TimeExperiment
numSamples = 10;
experiment = TimeExperiment.withFixedSampleSize(numSamples);
result = run(experiment,suite)
Running preallocationTest
.......... .......... .......... ..........
Done preallocationTest
__________


result = 

  1x4 TimeResult array with properties:

    Name
    Valid
    Samples
    TestActivity

Totals:
   4 Valid, 0 Invalid.
   10.0654 seconds testing time.

Alternatives

If you do not need to create an experiment and test suite explicitly, you can use runperf.

Version History

Introduced in R2016a

expand all