run
类: matlab.perftest.TimeExperiment
命名空间: matlab.perftest
对测试套件运行计时试验
说明
对测试套件运行计时试验,并返回由 results
= run(experiment
,suite
)TimeResult
对象组成的数组。results
中的每个元素对应于 suite
中的一个元素。
输入参数
experiment
— 用于采集测量值的试验
matlab.perftest.TimeExperiment
实例
用于采集测量值的试验,指定为 matlab.perftest.TimeExperiment
实例。
suite
— 测试套件
matlab.unittest.Test
数组
测试套件,指定为 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 中推出R2019a: 性能测试结果以 TimeResult
对象形式返回
run
方法返回包含指定时间试验结果的 matlab.perftest.TimeResult
数组。在以前的版本中,该方法返回由 matlab.unittest.measurement.MeasurementResult
对象组成的数组。
MATLAB 命令
您点击的链接对应于以下 MATLAB 命令:
请在 MATLAB 命令行窗口中直接输入以执行命令。Web 浏览器不支持 MATLAB 命令。
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)