measureMetrics(_:automaticallyStartMeasuring:for:)
Measures the performance of a block of code, optionally deferring the starting point for measurement.
Declaration
func measureMetrics(_ metrics: [XCTPerformanceMetric], automaticallyStartMeasuring: Bool, for block: () -> Void)Parameters
- metrics:
An array of performance metrics to measure. Each metric is measured across calls to the block. Pass Wallclocktime to measure the number of seconds taken to execute the block of code.
- automaticallyStartMeasuring:
If False, measurements will not be taken until Startmeasuring() is called inside the block.
- block:
A block whose performance is measured.
Discussion
Call this method from within a test method to measure the performance of a block of code. This method provides more granular control over performance measurement than the measure(_:) method, and should be used when you need to customize the points at which measurement starts and ends within the block, or wish to measure multiple metrics for the block.
Performance measurement must be started and stopped exactly once within the block. As a result:
If
automaticallyStartMeasuringis true and startMeasuring() is called inside the block, the test will fail.If
automaticallyStartMeasuringis false, startMeasuring() must be called once and only once before the end of the block, or the test will fail.If stopMeasuring() is called multiple times during the block the test will fail.