---
schema_version: "1"
id: 793db2b2ade3af84d7e51e9f6a33c9cc8fad8d36358e780cb43707a2229ae18e
title: duration
collection: mulesoft
version: current
locale: en-us
portal_url: https://docs.salesforce.com/mulesoft/current/en-us/dataweave/2.11/dw-timer-functions-duration.md
canonical_url: https://docs.mulesoft.com/dataweave/2.11/dw-timer-functions-duration
source_site: docs.mulesoft.com
content_type: documentation
content_hash: 2e5ddbe4d129860301a9b99907bf2640a465a756227a706cfc222451b5538cd4
description: MuleSoft Documentation Site
release: "2.11"
latest: false
---
---
product: DataWeave
version: 2.11
---

# duration

> For the full documentation index, see: https://docs.mulesoft.com/llms.txt

## duration<T>(valueToMeasure: () -> T): DurationMeasurement<T>

Executes the input function and returns an object with execution time in milliseconds and result of
that function.

### Parameters

<table><colgroup><col> <col></colgroup><thead><tr><th>Name</th><th>Description</th></tr></thead><tbody><tr><td><p><code>valueToMeasure</code></p></td><td><p>A function to pass to <code>duration</code>.</p></td></tr></tbody></table>

### Example

This example passes a `wait` function (defined in the header), which returns the execution time and
result of that function in a `DurationMeasurement` object.

#### Source

```Dataweave
%dw 2.0
output application/json
fun myFunction() = dw::Runtime::wait("My result",100)
---
dw::util::Timer::duration(() -> myFunction())
```

#### Output

```XML
{
  "time": 101,
  "result": "My result"
}
```
