<!--
{
  "availability" : [

  ],
  "documentType" : "symbol",
  "framework" : "XCTest",
  "identifier" : "/documentation/XCTest/XCTestCase/measure(_:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "XCTest"
    ],
    "preciseIdentifier" : "c:objc(cs)XCTestCase(im)measureBlock:"
  },
  "title" : "measure(_:)"
}
-->

# measure(_:)

Measures the performance of a block of code.

```
func measure(_ block: () -> Void)
```

## Parameters

`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. By default, this method measures the number of seconds the block of code takes to execute. Override [`defaultPerformanceMetrics`](/documentation/XCTest/XCTestCase/defaultPerformanceMetrics) to change the default metrics measured by this method.

> Note:
> This method starts and stops performance measurement automatically. Use ``doc://com.apple.xctest/documentation/XCTest/XCTestCase/measureMetrics(_:automaticallyStartMeasuring:for:)`` if you need more control over when performance measurement starts and ends.

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)