web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Suggested Answer

Set class

(3) ShareShare
ReportReport
Posted on by 1,965
Hi,

Is there a difference in performance? both give me the same result
so is is better to use set.in() or setEnumerator?
Set  set = new Set(Types::String);
SetEnumerator   setEnumerator;
while select...
{
    str x = this.get(...);
    if (x)
    {
       set.add(x);
    }

}

if (!set.empty())
{
   setEnumerator = set.getEnumerator();
   setEnumerator.reset();
   while (setEnumerator.moveNext())
   {
       if(this.existInTable1(setEnumerator.current())
       {
          contractClass = new ContractClass;
          contractClass.parmValue(setEnumerator.current());
          List1.addEnd(contractClass);
       }
   }
}


OR
 
Set  set = new Set(Types::String);
while select ....
{
    str x= this.get(..);
    if (x && !set.in(x)
    {
        set.add(x);
        if(this.existInTable1(x)
        {
          contractClass = new ContractClass;
          contractClass.parmValue(x);
          List1.addEnd(contractClass);
        }
    }

}
 
Categories:
I have the same question (0)
  • Anton Venter Profile Picture
    20,345 Super User 2025 Season 2 on at
    Hi,
     
    Not sure, the getEnumerator is the preferred method in my opinion. You can time the two methods using the .NET Stopwatch class.
     
    //stopwatch
    System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
    sw.Start();
    
    //add code to time here
    
    sw.Stop();
    info(strFmt("Done. Duration %1s.", sw.ElapsedMilliseconds/1000));
     
  • Suggested answer
    Martin Dráb Profile Picture
    237,880 Most Valuable Professional on at
    Iterating the collection takes some non-zero time, therefore not doing so is more efficient. But it won't make much difference if your collection isn't huge. I would rather suspect that get() and existInTable1() may be a performance problem; check out if you can't improve them (e.g. by replacing get() with SQL code in a view and use a noexists join with Table1). But that's just wild guessing without more information about these methods.
     
    You can also improve the latter approach by calling add() and checking it's return value, instead of calling in() and optionally add().

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Martin Dráb Profile Picture

Martin Dráb 611 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 529 Super User 2025 Season 2

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 285 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans