Link to home
Start Free TrialLog in
Avatar of Philippe Renaud
Philippe RenaudFlag for Canada

asked on

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 ?
Avatar of CuteBug
CuteBug
Flag of India image

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.
Avatar of Philippe Renaud

ASKER

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 = .....
Avatar of it_saige
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-
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.
ASKER CERTIFIED SOLUTION
Avatar of CuteBug
CuteBug
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Why did you choose the data structures that you did for this code? What was your goal when you made those choices?
Thanks, thats really fast.... amazing.