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

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