---
schema_version: "1"
id: 8de0b0ae14349997d6bab6a3aa70db93a633b83cee6ead13a5aa8cd086640456
title: duration
collection: mulesoft
version: current
locale: en-us
portal_url: https://docs.salesforce.com/mulesoft/current/en-us/dataweave/latest/dw-timer-functions-duration.md
canonical_url: https://docs.mulesoft.com/dataweave/latest/dw-timer-functions-duration
source_site: docs.mulesoft.com
content_type: documentation
content_hash: 351b421a5d3f365deeb0976da93a6aedc9b71937b7876076a4a645f253e22a8b
description: MuleSoft Documentation Site
release: "2.13"
latest: true
---
---
product: DataWeave
version: 2.13
is-latest-version: true
---

# 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"
}
```
