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

代替方法

明示的に実験とテスト スイートを作成する必要がない場合は、runperf を使用できます。

バージョン履歴

R2016a で導入

すべて展開する