Main Content

run

类: matlab.perftest.TimeExperiment
命名空间: matlab.perftest

对测试套件运行计时试验

说明

示例

results = run(experiment,suite) 对测试套件运行计时试验,并返回由 TimeResult 对象组成的数组。results 中的每个元素对应于 suite 中的一个元素。

输入参数

全部展开

用于采集测量值的试验,指定为 matlab.perftest.TimeExperiment 实例。

测试套件,指定为 matlab.unittest.Test 数组。

示例

全部展开

在您的当前工作文件夹中创建一个基于类的测试 preallocationTest.m,用于对不同的预分配方法进行比较。

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

创建一个测试套件。

suite = testsuite('preallocationTest');

构造一个采集固定数量的样本测量值的计时试验,并运行测试。

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.
   21.1282 seconds testing time.

备选方法

如果您不需要显式创建试验和测试套件,可以使用 runperf

版本历史记录

在 R2016a 中推出

全部展开