Instance Method

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 will be 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 should be 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 automaticallyStartMeasuring is true and startMeasuring() is called inside the block, the test will fail.

  • If automaticallyStartMeasuring is 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.

See Also

Measuring Performance

func measure(() -> Void)

Measures the performance of a block of code.

func startMeasuring()

Starts the measurement of performance metrics within a block of code.

func stopMeasuring()

Ends the measurement of performance metrics within a block of code.

class var defaultPerformanceMetrics: [XCTPerformanceMetric]

Identifies the performance metrics measured when measure(_:) is invoked.

struct XCTPerformanceMetric

Performance metrics that can be measured by XCTest.