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

C#

 
GeneralRe: How to report progress from Async function Pin
Mou_kol1-May-21 3:15
Mou_kol1-May-21 3:15 
GeneralRe: How to report progress from Async function Pin
OriginalGriff1-May-21 4:21
mveOriginalGriff1-May-21 4:21 
GeneralRe: How to report progress from Async function Pin
Mou_kol1-May-21 6:42
Mou_kol1-May-21 6:42 
AnswerRe: How to report progress from Async function Pin
Eddy Vluggen3-May-21 6:25
professionalEddy Vluggen3-May-21 6:25 
QuestionC# How to speed up for loop with large data iteration Pin
Mou_kol29-Apr-21 2:40
Mou_kol29-Apr-21 2:40 
AnswerRe: C# How to speed up for loop with large data iteration Pin
Richard Andrew x6429-Apr-21 2:46
professionalRichard Andrew x6429-Apr-21 2:46 
AnswerRe: C# How to speed up for loop with large data iteration Pin
Richard MacCutchan29-Apr-21 3:07
mveRichard MacCutchan29-Apr-21 3:07 
AnswerRe: C# How to speed up for loop with large data iteration Pin
OriginalGriff29-Apr-21 4:16
mveOriginalGriff29-Apr-21 4:16 
Richard is right:
Quote:
Which lines are taking the longest to execute?

And so is Richard:
Quote:
you need to understand that processing just over 2.5 million items will take some time.


The first part of any speed improvement exercise is to find out what you have: and that means timing your code to find out what takes a "long time" and what is "quick" - there is no point in trying to squeeze improvements out of fast code because that will make marginal difference; the slow code is teh bit that needs speeding up.
So start with the Stopwatch Class (System.Diagnostics) | Microsoft Docs[^] and start finding out where that code runs quick, and where it runs slow.
We can't do that for you: we don't have any access to your data, and it's likely to be very relevant to any speed analysis.

When you have that, you also have a metric for much improvement you are making as you go.

It's possible that you might be able to multithread it, to spread the load out over the whole processor - but that's not as simple as it may sound: although thinks like Parallel.Foreach exist, using threading blindly is as likely to slow down your whole computer as speed up processing, particularly when you start dealing with 2,000,000 items each of which probably don't take much time so the additional thread setup / processing overhead starts to overweigh the actual task.
You may get some good "throughput" improvements by splitting the for loop into a small number N of threads, each of which does 1/N th of the total task. But remember: List and DataTable are not considered thread safe, so you'll probably need to think very carefully before you start coding that if you don't want really hard to spot and track down data bugs.
As a general rule, I wouldn't recommend trying to use more threads than you have cores ...
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!

AnswerRe: C# How to speed up for loop with large data iteration Pin
Gerry Schmitz29-Apr-21 9:03
mveGerry Schmitz29-Apr-21 9:03 
GeneralRe: C# How to speed up for loop with large data iteration Pin
jsc4229-Apr-21 22:29
professionaljsc4229-Apr-21 22:29 
GeneralRe: C# How to speed up for loop with large data iteration Pin
Gerry Schmitz30-Apr-21 8:22
mveGerry Schmitz30-Apr-21 8:22 
GeneralRe: C# How to speed up for loop with large data iteration Pin
jsc421-May-21 9:42
professionaljsc421-May-21 9:42 
QuestionHow to configure ad hoc network using C# windows form app for windows 10 Pin
Member 1517286227-Apr-21 4:09
Member 1517286227-Apr-21 4:09 
AnswerRe: How to configure ad hoc network using C# windows form app for windows 10 Pin
Gerry Schmitz27-Apr-21 8:02
mveGerry Schmitz27-Apr-21 8:02 
Questionsql server 2019 instances with C # Pin
Member 1407213825-Apr-21 20:50
Member 1407213825-Apr-21 20:50 
AnswerRe: sql server 2019 instances with C # Pin
OriginalGriff25-Apr-21 21:13
mveOriginalGriff25-Apr-21 21:13 
AnswerRe: sql server 2019 instances with C # Pin
Eddy Vluggen26-Apr-21 10:59
professionalEddy Vluggen26-Apr-21 10:59 
Questioncomputer science Pin
A.R ENTERTAIN24-Apr-21 15:17
A.R ENTERTAIN24-Apr-21 15:17 
AnswerRe: computer science Pin
Dave Kreskowiak24-Apr-21 15:42
mveDave Kreskowiak24-Apr-21 15:42 
AnswerRe: computer science Pin
OriginalGriff24-Apr-21 19:14
mveOriginalGriff24-Apr-21 19:14 
AnswerRe: computer science Pin
Gerry Schmitz26-Apr-21 8:59
mveGerry Schmitz26-Apr-21 8:59 
AnswerRe: computer science Pin
SeanChupas26-Apr-21 9:38
SeanChupas26-Apr-21 9:38 
AnswerRe: computer science Pin
Eddy Vluggen26-Apr-21 11:07
professionalEddy Vluggen26-Apr-21 11:07 
AnswerRe: computer science Pin
Mycroft Holmes26-Apr-21 12:17
professionalMycroft Holmes26-Apr-21 12:17 
AnswerRe: computer science Pin
Pete O'Hanlon26-Apr-21 20:54
mvePete O'Hanlon26-Apr-21 20:54 

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.