Main Content

matlab.perftest.TimeExperiment.withFixedSampleSize

クラス: matlab.perftest.TimeExperiment
名前空間: matlab.perftest

固定数の測定による時間実験を構築

説明

experiment = matlab.perftest.TimeExperiment.withFixedSampleSize(numSamples) は、固定数の測定による時間実験を構築します。このメソッドは FixedTimeExperiment のインスタンスを返します。

experiment = matlab.perftest.TimeExperiment.withFixedSampleSize(numSamples,'NumWarmups',numWarmups) は、時間実験がまずコードを numWarmups 回実行してウォームアップするように設定します。

入力引数

すべて展開する

収集するサンプル測定値の数。正の整数として指定します。ウォームアップの回数を指定した場合、テスト フレームワークはまずコードを numWarmups 回実行してから、numSamples 個の測定値を収集します。

ウォームアップ測定の数。非負の整数として指定します。numWarmups はテスト フレームワークがウォームアップのためにテスト コードを実行する回数を定義します。コードをウォームアップすることで 1 回目の実行コストの影響を最小限に抑えることができ、一般的な実行時間をより現実的に解析できます。

例: experiment = matlab.perftest.TimeExperiment.withFixedSampleSize(24,'NumWarmups',8) は、ウォームアップとしてコードを 8 回実行してから、コードを 24 回実行してサンプル測定値を収集する FixedTimeExperiment を構築します。

すべて展開する

現在の作業フォルダーに、さまざまな事前割り当てメソッドを比較するクラスベースのテスト 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 = 6;
experiment = TimeExperiment.withFixedSampleSize(numSamples);
result = run(experiment,suite);
Running preallocationTest
..........
..........
....
Done preallocationTest
__________

4 番目のテストのテスト アクティビティを表示します。

result(4).TestActivity
ans = 

                Name                 Passed    Failed    Incomplete    MeasuredTime    Objective         Timestamp             Host        Platform           Version                      TestResult                          RunIdentifier            
    _____________________________    ______    ______    __________    ____________    _________    ____________________    ___________    ________    _____________________    ________________________________    ____________________________________

    preallocationTest/testForLoop    true      false     false         0.90553         sample       29-Dec-2015 12:14:55    MY-HOSTNAME    win64       9.0.0.320924 (R2016a)    [1x1 matlab.unittest.TestResult]    a07f34c0-5653-4e01-b814-118fe30d3adf
    preallocationTest/testForLoop    true      false     false         0.86564         sample       29-Dec-2015 12:14:56    MY-HOSTNAME    win64       9.0.0.320924 (R2016a)    [1x1 matlab.unittest.TestResult]    a07f34c0-5653-4e01-b814-118fe30d3adf
    preallocationTest/testForLoop    true      false     false         0.75888         sample       29-Dec-2015 12:14:57    MY-HOSTNAME    win64       9.0.0.320924 (R2016a)    [1x1 matlab.unittest.TestResult]    a07f34c0-5653-4e01-b814-118fe30d3adf
    preallocationTest/testForLoop    true      false     false         0.74051         sample       29-Dec-2015 12:14:58    MY-HOSTNAME    win64       9.0.0.320924 (R2016a)    [1x1 matlab.unittest.TestResult]    a07f34c0-5653-4e01-b814-118fe30d3adf
    preallocationTest/testForLoop    true      false     false          0.8735         sample       29-Dec-2015 12:14:58    MY-HOSTNAME    win64       9.0.0.320924 (R2016a)    [1x1 matlab.unittest.TestResult]    a07f34c0-5653-4e01-b814-118fe30d3adf
    preallocationTest/testForLoop    true      false     false         0.83188         sample       29-Dec-2015 12:14:59    MY-HOSTNAME    win64       9.0.0.320924 (R2016a)    [1x1 matlab.unittest.TestResult]    a07f34c0-5653-4e01-b814-118fe30d3adf

このパフォーマンス テストでは各テストで 6 個のサンプル測定値を収集しました。

ウォームアップとしてさらにコードを 3 回実行する時間実験を構築します。テストを実行します。

numWarmups = 3;
experiment = TimeExperiment.withFixedSampleSize(numSamples,'NumWarmups',numWarmups);
result = run(experiment,suite);
Running preallocationTest
..........
..........
....
Done preallocationTest
__________

4 番目のテストのテスト アクティビティを表示します。

result(4).TestActivity
ans = 

                Name                 Passed    Failed    Incomplete    MeasuredTime    Objective         Timestamp             Host        Platform           Version                      TestResult                          RunIdentifier            
    _____________________________    ______    ______    __________    ____________    _________    ____________________    ___________    ________    _____________________    ________________________________    ____________________________________

    preallocationTest/testForLoop    true      false     false         0.82972         warmup       29-Dec-2015 12:21:59    MY-HOSTNAME    win64       9.0.0.316358 (R2016a)    [1x1 matlab.unittest.TestResult]    37da664a-feba-4277-975f-3d71bcbac71a
    preallocationTest/testForLoop    true      false     false         0.85917         warmup       29-Dec-2015 12:22:00    MY-HOSTNAME    win64       9.0.0.316358 (R2016a)    [1x1 matlab.unittest.TestResult]    37da664a-feba-4277-975f-3d71bcbac71a
    preallocationTest/testForLoop    true      false     false         0.85857         warmup       29-Dec-2015 12:22:01    MY-HOSTNAME    win64       9.0.0.316358 (R2016a)    [1x1 matlab.unittest.TestResult]    37da664a-feba-4277-975f-3d71bcbac71a
    preallocationTest/testForLoop    true      false     false         0.85307         sample       29-Dec-2015 12:22:02    MY-HOSTNAME    win64       9.0.0.316358 (R2016a)    [1x1 matlab.unittest.TestResult]    37da664a-feba-4277-975f-3d71bcbac71a
    preallocationTest/testForLoop    true      false     false         0.86655         sample       29-Dec-2015 12:22:03    MY-HOSTNAME    win64       9.0.0.316358 (R2016a)    [1x1 matlab.unittest.TestResult]    37da664a-feba-4277-975f-3d71bcbac71a
    preallocationTest/testForLoop    true      false     false         0.81533         sample       29-Dec-2015 12:22:04    MY-HOSTNAME    win64       9.0.0.316358 (R2016a)    [1x1 matlab.unittest.TestResult]    37da664a-feba-4277-975f-3d71bcbac71a
    preallocationTest/testForLoop    true      false     false         0.88266         sample       29-Dec-2015 12:22:04    MY-HOSTNAME    win64       9.0.0.316358 (R2016a)    [1x1 matlab.unittest.TestResult]    37da664a-feba-4277-975f-3d71bcbac71a
    preallocationTest/testForLoop    true      false     false         0.94436         sample       29-Dec-2015 12:22:05    MY-HOSTNAME    win64       9.0.0.316358 (R2016a)    [1x1 matlab.unittest.TestResult]    37da664a-feba-4277-975f-3d71bcbac71a
    preallocationTest/testForLoop    true      false     false          1.0375         sample       29-Dec-2015 12:22:07    MY-HOSTNAME    win64       9.0.0.316358 (R2016a)    [1x1 matlab.unittest.TestResult]    37da664a-feba-4277-975f-3d71bcbac71a

各テストで、パフォーマンス テスト フレームワークは 6 個のサンプル測定値に加えて、3 個のウォームアップ測定値を収集しました。

バージョン履歴

R2016a で導入