<!--
{
  "availability" : [
    "iOS: 13.0.0 -",
    "iPadOS: 13.0.0 -",
    "macCatalyst: 13.0.0 -",
    "tvOS: 13.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 7.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "XCTest",
  "identifier" : "/documentation/XCTest/XCTCPUMetric",
  "metadataVersion" : "0.1.0",
  "role" : "Class",
  "symbol" : {
    "kind" : "Class",
    "modules" : [
      "XCTest"
    ],
    "preciseIdentifier" : "c:objc(cs)XCTCPUMetric"
  },
  "title" : "XCTCPUMetric"
}
-->

# XCTCPUMetric

A metric to record information about CPU activity during a performance test.

```
class XCTCPUMetric
```

## Overview

`XCTCPUMetric` captures the following statistics about CPU activity; each metric is captured while the block argument to a [`measure(metrics:block:)`](/documentation/XCTest/XCTestCase/measure(metrics:block:)) call runs in a performance test:

- *CPU time* is the length of time, in seconds, that the CPU is active and executing instructions for the measured target. When the CPU switches context to execute a different process or thread or becomes idle, this value doesn’t increase.
- *CPU cycles* is the number of clock cycles that occur while the CPU is active and executing instructions for the measured target.
- *CPU instructions retired* is the number of processor instructions that run to completion during execution of the measured target. It’s possible for a CPU to abandon processing an instruction during execution, for example, if the instruction is evaluated out of order and logically follows a branch in the code that the CPU discovers it doesn’t need to take. An abandoned instruction doesn’t contribute to the retired instructions metric.

## Topics

### Initializers

[`init()`](/documentation/XCTest/XCTCPUMetric/init())

Creates a CPU metric that records data for the current process.

[`init(application:)`](/documentation/XCTest/XCTCPUMetric/init(application:))

Creates a CPU metric that records data for the requested app.

[`init(limitingToCurrentThread:)`](/documentation/XCTest/XCTCPUMetric/init(limitingToCurrentThread:))

Creates a CPU metric that optionally records data only for the current thread.



---

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)