keepMeasuring
类: matlab.perftest.TestCase
命名空间: matlab.perftest
使用自动循环测量代码
说明
keepMeasuring(
指示测试框架根据需要对 testcase
)while
循环进行多次迭代,以获得准确的性能测量结果。
对于执行速度太快以至于 MATLAB® 不能准确测量其时间的性能测试,将通过假设失败将其滤除。使用 keepMeasuring
方法,测试框架可以通过自动确定代码迭代次数并测量平均性能来显著加快代码测量速度。
您不能在对 startMeasuring
和 stopMeasuring
的调用之间放置 keepMeasuring-while
循环。同样,您不能在 keepMeasuring-while
循环内调用 startMeasuring
和 stopMeasuring
方法。
输入参数
testcase
— 测试用例的实例
matlab.perftest.TestCase
对象
测试用例的实例,指定为 matlab.perftest.TestCase
对象。
label
— 测量边界标签
有效的 MATLAB 标识符
测量边界标签,指定为有效的 MATLAB 标识符。有效的 MATLAB 标识符是由字母数字(A
–Z
、a
–z
、0
–9
)和下划线构成的字符向量或字符串标量,第一个字符应为字母且字符向量长度须小于或等于 namelengthmax
。
示例
测量快速代码
创建性能测试类 ZerosTest
。此参数化性能测试对三种不同大小的由零组成的数组的创建进行测量。
classdef ZerosTest < matlab.perftest.TestCase properties (TestParameter) Size = {1e2,1e3,1e4}; end methods(Test) function testOne(testCase,Size) A = zeros(Size); end end end
运行性能测试。创建前两个数组的时间太接近框架的精度,因而测试被滤除。
results = runperf('ZerosTest');
Running ZerosTest ........ ================================================================================ ZerosTest/testOne(Size=100) was filtered. Test Diagnostic: The MeasuredTime should not be too close to the precision of the framework. Details ================================================================================ .. ...... ================================================================================ ZerosTest/testOne(Size=1000) was filtered. Test Diagnostic: The MeasuredTime should not be too close to the precision of the framework. Details ================================================================================ .... .... ================================================================================ ZerosTest/testOne(Size=10000) was filtered. Test Diagnostic: The MeasuredTime should not be too close to the precision of the framework. Details ================================================================================ Done ZerosTest __________ Failure Summary: Name Failed Incomplete Reason(s) ============================================================================ ZerosTest/testOne(Size=100) X Filtered by assumption. ---------------------------------------------------------------------------- ZerosTest/testOne(Size=1000) X Filtered by assumption. ---------------------------------------------------------------------------- ZerosTest/testOne(Size=10000) X Filtered by assumption.
要获得准确的测量结果,请修改 ZerosTest
类以使用 keepMeasuring-while
循环。性能测试框架测量 keepMeasuring-while
循环内的代码。
classdef ZerosTest < matlab.perftest.TestCase properties (TestParameter) Size = {1e2,1e3,1e4}; end methods(Test) function testOne(testCase,Size) while(testCase.keepMeasuring) A = zeros(Size); end end end end
重新运行性能测试。
results = runperf('ZerosTest');
Running ZerosTest .......... .......... .......... .......... .......... .......... .......... .......... .......... .......... .......... .......... .......... .......... .......... .......... .......... .......... .......... ....... Done ZerosTest __________
版本历史记录
在 R2018b 中推出
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)