C# Dictionary Loop Enhancment

Posted by Toto on Stack Overflow See other posts from Stack Overflow or by Toto
Published on 2010-03-09T10:16:25Z Indexed on 2010/03/09 10:36 UTC
Read the original article Hit count: 171

Filed under:
|
|

Hi,

I have a dictionary with around 1 milions items. I am constantly looping throw the dictionnary :

    public void DoAllJobs()
    {
            foreach (KeyValuePair<uint, BusinessObject> p in _dictionnary)
            {
                if(p.Value.MustDoJob)
                    p.Value.DoJob();
            }
    }

The execution is a bit long, around 600 ms, I would like to deacrese it. Here is the contraints :

  1. MustDoJob values mostly stay the same beetween two calls to DoAllJobs()
  2. 60-70% of the MustDoJob values == false
  3. From time to times MustDoJob change for 200 000 pairs.
  4. Some p.Value.DoJob() can not be computed at the same time (COM object call)
  5. Here, I do not need the key part of the _dictionnary objet but I really do need it somewhere else

I wanted to do the following :

  • Parallelizes but I am not sure is going to be effective due to 4.
  • Sorts the dictionnary since 1. and 2. (and stop want I find the first MustDoJob == false) but I am wondering what 3. would result in

I did not implement any of the previous ideas since it could be a lot of job and I would like to investigate others options before. So...any ideas ?

© Stack Overflow or respective owner

Related posts about c#

Related posts about dictionary