Philippe Renaud
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(Date Interval.D ay, 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 ?
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(Date
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 ?
ASKER
sorry right after :
For x As Integer = 0 To last.Count - 1
im using :
Dim arrString = last(x).Split(New String() {","}, StringSplitOptions.RemoveE mptyEntrie s)
then i do the Dim q = .....
For x As Integer = 0 To last.Count - 1
im using :
Dim arrString = last(x).Split(New String() {","}, StringSplitOptions.RemoveE
then i do the Dim q = .....
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-
What does each item in last have contained within it?
What do the KeyValuePair(Of Date, String) in the dictionary represent?
-saige-
ASKER
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.
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Why did you choose the data structures that you did for this code? What was your goal when you made those choices?
ASKER
Thanks, thats really fast.... amazing.
Seems you are not using x anywhere and you are running the same code last.Count times.