c# - Strange slowness while iterating over Linq result -
While searching for a recent time, I saw that the algorithm looked slow. Deeply deeply I found that it was not a linq code, but it took long after the result of the output. (So far I have noticed that the success for Mark Budget Beat to kill slickest Linq.)
code:
DateTime dt = DateTime.Now; Console.lightline ("alge start" + dt. Second + "." + Dt. Milliseconds); Var qry = enumerable.Range (100000, 999999) Let's s = l.ToString () Let sReversed = New String (S. Riversse). From ToArray ()) I select Enumerable.Range (3, 9) two T = (L * I). Ostring () where T == sreversed new {l, i}; DT = DateTime.Now; Console.lightline ("alge and" + dt.Second + "." + Dt.Millisecond); Foreach (var row in curie) console Virite line ("{0} x {1} = {2}", line.l, row.i, line.l * row.i); DT = DateTime.Now; Console.lightline ("disp and" + dt. Seconds + "." + Dt. milliseconds);
Output:
Algee 20.257 alg and 20.270 10 99 9 x 9 = 989901 219978 x 4 = 879912 10 99 8 9 9 = 9899901disp end 31.322
. To display 13 seconds and display over 11?!? What is the reason for this?
The reason for this is that unless you describe it, In objects in LINQ it only sets up a group of delegates, which are called upon when you are repeated on the calculator. If you were to add a ToList () to the query, you will see that the time taken will be in the set and away from the display.
Comments
Post a Comment