This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

run

Class: matlab.perftest.TimeExperiment
Package: matlab.perftest

Run time experiment on test suite

Syntax

results = run(experiment,suite)

Description

example

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.

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.

Alternatives

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

Introduced in R2016a