Performance check between For loop and Destination Rule – Plan per Slot (No Destinations) with dynamic slot count.
In practical scenarios, we come across the situation where we need to perform the task for number of users or a specific number of time. For such scenarios, we need to iterate for each item so that we can take required action for them.
For example I would like to add details for number of products returned by SMO. As number of products returned by SMO can be more than one, so I need to iterate for each item returned by SMO and then add it’s details in table.
As a Techie, while coding or designing My basic responsibilities are to provide efficient, reliable and fast execution code.
Execution time of code doesn’t matter for some applications, but some time it affects performance. So, we always need to look around for other possible solutions.
So, I can do this using any one of the following two ways:
- ForEach loop
- Destination Rule (Plan Per Slot – no Destinations)
As I previously told I need more efficient solution for my problem. So let’s check with small Workflow, which one is more efficient.
I have designed a workflow having both for loop and Using Destination Rule (Plan Per Slot – no Destinations), to perform comparison on execution time taken by each.
Activity 1: This activity Records the time stamp which I am going to use as start time for my “for loop”.
Activity 2: This activity has For loop event which get source from SMO and returns two Outcomes based on received result from SMO.
Activity 3: This activity records the products details into table (here with products name I am passing time stamp so that we can trace it exactly time taken by each iteration)
Activity 4: This activity records the time stamp, which I will use as End time for my “for loop” and Start time for “Destination Rule”.
Activity 5: This activity has “Destination Rule” Plan per slot (no Destinations).
(To enable this option please check advanced option and click next)
In destination Rule, I have selected option “select a list field to determine how many slots should be created.” And used same SMO which was used in “for loop” (gives returns the list of products).
Now I am required to record All products details to table. And to achieve same, I have used SMO event where I am passing every product details to SMO event so that it can be recorded in Audit table.
Activity 6: This activity records the time stamp, which I will use as End time for “Destination Rule”.
After running It I got below results, With Execution time difference in both
For loop have took 5 seconds to log 10 items to data base where as the other method Destination Rule method took just 1 second to log 10 items.
So conclusion here is Destination Rule method is much faster than for loop.