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

C#

 
GeneralRe: how to get the value of a control in a process which start with Process.start Pin
Richard MacCutchan1-May-13 21:02
mveRichard MacCutchan1-May-13 21:02 
QuestionSaving DrawLine to Image: SOLVED Pin
Member 792126830-Apr-13 3:34
Member 792126830-Apr-13 3:34 
AnswerRe: Saving DrawLine to Image Pin
Eddy Vluggen30-Apr-13 4:05
professionalEddy Vluggen30-Apr-13 4:05 
GeneralRe: Saving DrawLine to Image Pin
Member 792126830-Apr-13 5:11
Member 792126830-Apr-13 5:11 
AnswerRe: Saving DrawLine to Image Pin
Kenneth Haugland30-Apr-13 4:42
mvaKenneth Haugland30-Apr-13 4:42 
GeneralRe: Saving DrawLine to Image Pin
Member 79212681-May-13 0:46
Member 79212681-May-13 0:46 
AnswerRe: Saving DrawLine to Image: SOLVED Pin
Member 79212681-May-13 4:39
Member 79212681-May-13 4:39 
QuestionThe performance of LINQ vs. traditional iteration Pin
Rob Philpott30-Apr-13 3:30
Rob Philpott30-Apr-13 3:30 
Here's a program which creates 100 million random numbers, then counts how many are divisible by seven using three different methods:
C#
static void Main(string[] args)
{
    // create an array of 100 million random integers
    Random r = new Random(Environment.TickCount);
    int[] numbers = new int[100000000];
    for (int index = 0; index < numbers.Length; index++)
    {
        numbers[index] = r.Next();
    }

    // find number divisible by 7 using basic iteration
    Stopwatch sw = Stopwatch.StartNew();
    int count = 0;
    foreach (int number in numbers) if (number % 7 == 0) count++;
    Console.WriteLine("Simple Iteration {0} : {1}", count, sw.ElapsedMilliseconds);

    // now do the same in LINQ
    sw = Stopwatch.StartNew();
    var x = from g in numbers where g % 7 == 0 select g;
    count = x.Count();
    Console.WriteLine("LINQ Query {0} : {1}", count, sw.ElapsedMilliseconds);

    // now using just count
    sw = Stopwatch.StartNew();
    int z = numbers.Count(g => g % 7 == 0);
    Console.WriteLine("Count Query {0} : {1}", z, sw.ElapsedMilliseconds);

    Console.ReadLine();
}


If you run it, you'll find that the Select query(2nd) takes almost exactly twice as long as basic iteration (1st), the count method (3rd) takes about three times as long.

This is a similar program to one I wrote when LINQ came out, and it rather put me off. Not only did the LINQ look more confusing, but it took twice as long to execute. It's also harder to debug, of course.

So, interested in views on this. Can anyone adjust the app so the performance becomes similar? Because, unless I'm missing something, half the performance is a serious issue in a real-time system and something to avoid everywhere else.
Regards,
Rob Philpott.

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 
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 

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.