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

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