<!--
{
  "availability" : [
    "iOS: 26.0.0 -",
    "iPadOS: 26.0.0 -",
    "macCatalyst: 26.0.0 -",
    "macOS: 26.0.0 -",
    "tvOS: 26.0.0 -",
    "visionOS: 26.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Metal",
  "identifier" : "/documentation/Metal/MTL4ComputeCommandEncoder/writeTimestamp(granularity:counterHeap:index:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Metal"
    ],
    "preciseIdentifier" : "c:objc(pl)MTL4ComputeCommandEncoder(im)writeTimestampWithGranularity:intoHeap:atIndex:"
  },
  "title" : "writeTimestamp(granularity:counterHeap:index:)"
}
-->

# writeTimestamp(granularity:counterHeap:index:)

Writes a GPU timestamp into a heap.

```
func writeTimestamp(granularity: MTL4TimestampGranularity, counterHeap: any MTL4CounterHeap, index: Int)
```

## Parameters

`granularity`

[`MTL4TimestampGranularity`](/documentation/Metal/MTL4TimestampGranularity) hint to Metal about acceptable the level of precision.

`counterHeap`

[`MTL4CounterHeap`](/documentation/Metal/MTL4CounterHeap) to write timestamps into.

`index`

The index value into which Metal writes the timestamp.

## Discussion

The method ensures that any prior work finishes, but doesn’t delay any subsequent work.

You can alter this command’s behavior through the `granularity` parameter.

- Pass [`MTL4TimestampGranularity.relaxed`](/documentation/Metal/MTL4TimestampGranularity/relaxed) to allow Metal to provide timestamps with
  minimal impact to runtime performance, but with less detail. For example, the command may group all timestamps for
  a pass together.
- Pass [`MTL4TimestampGranularity.precise`](/documentation/Metal/MTL4TimestampGranularity/precise) to request that Metal provides timestamps
  with the most detail. This can affect runtime performance.

---

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)