page contents

Collection Classes - Iteration performance


Collection Classes are very popular and frequently used composite data types within the Microsoft Dynamics AX developers’ community.
The idea is to have generic collections, which provide you the ability to create and maintain in-memory collections of any type of objects at run-time.
In many business scenarios, there is a need to iterate through the collection members and perform relevant activities on these collection members.

This post is investigating the iteration performance through the collection members of different available Collection Class types and in this way tries to help you making the right decision when utilizing Collection Classes in your own code.

Scenario
This post is making use of a test script which is initializing different local variables, each of a different Collection Class Type (i.e. Set, List, Map, Array), and iterating though all elements of these in-memory collections.
It is important to notice that the different collections will have all the same number of elements. To make the results more sensible, we repeat the test for a given number of times and provide you the total elapsed number of Ticks for the whole loop. Please also note that the used script is running the code on both client and server side, which will also give us more insight about the different execution options.

Execution results
Here bellow, you have the execution results of the attached test script:

Collection Classes - Iteration Performance - Results

Conclusion
The results are showing the following facts:

  • We might order the iteration performance as followed:
        Array-by-index < Map-Enumerator < Set-Enumerator < List-Enumerator < List-Iterator
    performing best to least from left to right.
  • Code execution on the Server-side is incredibly faster than on the Client-side,
    which shows again, it is better to run the code on the Server-side whenever possible, even if you do not have any database interactions.

Downloads
Conllection Class- Ieteration Test Script

Skip to main content