Speed up my loops

Hi EE, I have a vb.net form that has 2 FOR Loops and inside the first loop i have a Query LINQ that get some information ....
bottom line... its really slow... it could take something like 45 minutes to compute everything....

I am not aware of new ways of coding that could speed up this. for example, i just learned about PLINQ but would that help me, i dont know..is there anything

my code is the follwing :

For x As Integer = 0 To last.Count - 1   (which is about 2415 loops)
      'MyItems has about 8900 items in it, its a dictionnary of Date, String

    'q will always ahve about between 600 to 700 items in it....
            Dim q = (From m In MyItems
                    Where arrString.All(Function(v) m.Value.Contains(v))
                    Select m)

            For y As Integer = 0 To q.Count - 1
                If y + 1 < q.Count Then
                    listDiff.Add(DateDiff(DateInterval.Day, q(y).Key, q(y + 1).Key))
                End If
            Next
Next

so this is the code I was talking about... and its long... any idea how I could speed up by minutes ?
LVL 1
PhilippeRenaudAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

CuteBugCommented:
Where are you using 'x'  in this code?
Seems you are not using x anywhere and you are running the same code last.Count times.
0
PhilippeRenaudAuthor Commented:
sorry right after :

For x As Integer = 0 To last.Count - 1
im using :

Dim arrString = last(x).Split(New String() {","}, StringSplitOptions.RemoveEmptyEntries)
then i do the Dim q = .....
0
it_saigeDeveloperCommented:
What is last made up of?
What does each item in last have contained within it?
What do the KeyValuePair(Of Date, String) in the dictionary represent?

-saige-
0
Cloud Class® Course: Certified Penetration Testing

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

PhilippeRenaudAuthor Commented:
1) Last is a list (Of String) there are around 2415 rows.
in it its combinations of numbers 9but as string) like this :

"01,02"
"01,03"
"01,04"
....
"28,45"

2415 rows of those...


2) in the dictionary, the key is a date, and the value is a long string of number
lets say:  

11/11/2014 ,   "04, 08, 11, 12, 13, 14, 24, 56, 69"

so what I do is that i look for for the last(x) that is "01,02" does it contains in the dicitonnary and return me all the rows with the LINQ.
then I loop the results and I get the dateInterval between every rows.
0
CuteBugCommented:
Try this:

For x As Integer = 0 To last.Count - 1 
	Dim arrString = last(x).Split(New String() {","}, StringSplitOptions.RemoveEmptyEntries)

	'q will select the dates from MyItems which contain last(x) in it
             Dim q = (From m In MyItems
                     Where arrString.All(Function(v) m.Value.Contains(v))
                     Select m.Key)

	     ' Get the day difference between adjacent dates
	     Dim diff = q.Zip(q.Skip(1), Function(d1, d2) DateDiff(DateInterval.Day, d1, d2));

	     For Each item In diff
    		listDiff.Add(item)
  	     Next item
Next

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
käµfm³d 👽Commented:
Why did you choose the data structures that you did for this code? What was your goal when you made those choices?
0
PhilippeRenaudAuthor Commented:
Thanks, thats really fast.... amazing.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.