Click here to Skip to main content
15,887,343 members
Home / Discussions / C#
   

C#

 
QuestionThe performance of LINQ vs. traditional iteration Pin
Rob Philpott30-Apr-13 3:30
Rob Philpott30-Apr-13 3:30 
AnswerRe: The performance of LINQ vs. traditional iteration Pin
Eddy Vluggen30-Apr-13 4:01
professionalEddy Vluggen30-Apr-13 4:01 
GeneralRe: The performance of LINQ vs. traditional iteration Pin
Rob Philpott30-Apr-13 4:31
Rob Philpott30-Apr-13 4:31 
GeneralRe: The performance of LINQ vs. traditional iteration Pin
harold aptroot30-Apr-13 8:33
harold aptroot30-Apr-13 8:33 
GeneralRe: The performance of LINQ vs. traditional iteration Pin
Rob Philpott30-Apr-13 8:44
Rob Philpott30-Apr-13 8:44 
GeneralRe: The performance of LINQ vs. traditional iteration Pin
harold aptroot30-Apr-13 8:54
harold aptroot30-Apr-13 8:54 
GeneralRe: The performance of LINQ vs. traditional iteration Pin
Eddy Vluggen30-Apr-13 9:42
professionalEddy Vluggen30-Apr-13 9:42 
AnswerRe: The performance of LINQ vs. traditional iteration Pin
Simon_Whale30-Apr-13 4:03
Simon_Whale30-Apr-13 4:03 
I have found that sometimes LinQ is slower than traditional for loops, with your example being on that I have seen first Hand too.

But recently I compared doing a product of calculation of a series of decimal numbers both with LinQ and a for loop for a project that I am working on. The LinQ for me out performed the

C#
List<int> data = new List<int>();

for (int i = 0; i < 100; i++) data.Add(i);

Stopwatch sw = Stopwatch.StartNew();

int value = 1;

for (int i = 0; i < 99; i++)
{
 value *= data[i];
}

Console.WriteLine(";Simple Iteration time {0}", sw.Elapsed.TotalMilliseconds);

sw = Stopwatch.StartNew();

int linqAgg = data.Aggregate((first, second) =>; first * second);

Console.WriteLine("Linq Iteration time {0}", sw.Elapsed.TotalMilliseconds );
Console.ReadLine();


my results are as follow

Simple Iteration time 1.7021
Linq Iteration time 0.6478

My personal feeling for the use of LinQ is to use with caution when speed is the most important factor.
Every day, thousands of innocent plants are killed by vegetarians.

Help end the violence EAT BACON

GeneralRe: The performance of LINQ vs. traditional iteration Pin
Rob Philpott30-Apr-13 4:24
Rob Philpott30-Apr-13 4:24 
GeneralRe: The performance of LINQ vs. traditional iteration Pin
Simon_Whale30-Apr-13 4:46
Simon_Whale30-Apr-13 4:46 
GeneralRe: The performance of LINQ vs. traditional iteration Pin
Rob Philpott30-Apr-13 4:57
Rob Philpott30-Apr-13 4:57 
GeneralRe: The performance of LINQ vs. traditional iteration Pin
Simon_Whale30-Apr-13 5:32
Simon_Whale30-Apr-13 5:32 
AnswerRe: The performance of LINQ vs. traditional iteration Pin
Freak3030-Apr-13 4:36
Freak3030-Apr-13 4:36 
AnswerRe: The performance of LINQ vs. traditional iteration Pin
Dave Kreskowiak30-Apr-13 5:17
mveDave Kreskowiak30-Apr-13 5:17 
AnswerRe: The performance of LINQ vs. traditional iteration Pin
Pete O'Hanlon30-Apr-13 6:38
mvePete O'Hanlon30-Apr-13 6:38 
GeneralRe: The performance of LINQ vs. traditional iteration Pin
Rob Philpott30-Apr-13 6:49
Rob Philpott30-Apr-13 6:49 
GeneralRe: The performance of LINQ vs. traditional iteration Pin
Simon_Whale30-Apr-13 23:41
Simon_Whale30-Apr-13 23:41 
AnswerRe: The performance of LINQ vs. traditional iteration Pin
Richard Deeming30-Apr-13 7:24
mveRichard Deeming30-Apr-13 7:24 
GeneralRe: The performance of LINQ vs. traditional iteration Pin
Rob Philpott30-Apr-13 7:54
Rob Philpott30-Apr-13 7:54 
AnswerRe: The performance of LINQ vs. traditional iteration Pin
jschell30-Apr-13 9:54
jschell30-Apr-13 9:54 
QuestionCrystal Report without preview print is not working in published file Pin
swathipd30-Apr-13 0:34
swathipd30-Apr-13 0:34 
AnswerRe: Crystal Report without preview print is not working in published file Pin
Eddy Vluggen30-Apr-13 1:00
professionalEddy Vluggen30-Apr-13 1:00 
GeneralRe: Crystal Report without preview print is not working in published file Pin
swathipd1-May-13 19:00
swathipd1-May-13 19:00 
GeneralRe: Crystal Report without preview print is not working in published file Pin
Eddy Vluggen2-May-13 11:00
professionalEddy Vluggen2-May-13 11:00 
QuestionC# IE toolbar button runs bat or PS script. works one time then doesn't anymore. Pin
Member 990412330-Apr-13 0:19
Member 990412330-Apr-13 0:19 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.