dev-resources.site
for different kinds of informations.
Using time() and duration() in DataWeave for performance check
Published at
3/21/2023
Categories
mulesoft
dataweave
performance
programming
Author
devalexmartinez
Author
15 person written this
devalexmartinez
open
You can use duration()
to get the total number of milliseconds it took to execute a function.
Script:
%dw 2.0
output application/json
import duration from dw::util::Timer
fun myFunc() = [1, 2, 3] reduce $+$$
---
duration(() -> myFunc())
Output:
{
"time": 0,
"result": 6
}
You can use time()
to get an even more detailed result of when the function started and ended. This will give you more insight into the total time it took to execute.
Script:
%dw 2.0
output application/json
import time from dw::util::Timer
fun myFunc() = [1, 2, 3] reduce $+$$
---
time(() -> myFunc())
Output:
{
"start": "2023-03-21T16:00:21.487377Z",
"result": 6,
"end": "2023-03-21T16:00:21.487408Z"
}
This way you can use -
to get the total number of time.
Script:
%dw 2.0
output application/json
import time from dw::util::Timer
fun myFunc() = [1, 2, 3] reduce $+$$
var funcResult = time(() -> myFunc())
---
funcResult.end - funcResult.start
Output:
"PT0.000024S"
dataweave Article's
7 articles in total
Using time() and duration() in DataWeave for performance check
currently reading
Main difference between 'do' and 'using' operators in DataWeave
read article
Develop your Battlesnake using a MuleSoft API & DataWeave with this starter project
read article
How to generate shareable link examples from GitHub to open in the DataWeave Playground
read article
How to move your code from the DataWeave Playground to Visual Studio Code
read article
DataWeave: accept lambda as parameter of a function
read article
How to access Secure Properties in DataWeave 2.0
read article
Featured ones: