Click here to Skip to main content
14,976,809 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi all,

I have made an application that reads a lot of files and processes the contents. This content can change.

Sometimes the application is very slow. I know this could be because of a file is large. But I never find out what file. So I want to make a performance counter. This is what I had in mind:

1. Application starts
2. Each time a file is read and processed I save the amount of time (or ticks) that the application used to read and process that file.
3. Repeat step 2 for all files (20 or so).
4. Check if the time (or ticks) or the previous run is more than 25%. If so: Warning.
5. Application ends and shows a report with values of step 4

Problems here is that it is never very accurate. If a file is done in 0,25 ms and the next time 0,50 ms it's already 25% more. But the next run the same file is done in 0,25 ms. What I want is a very accurate counter on the performance.

Has anyone any idea how this can be accomplished in the best way?


1 solution

Have you eliminated all other bottlenecks and positively identified that it is only the IO opertation that is causing the issue - there are probably other areas of your code that you can save some time on - you can't really improve the perfromance of the actual IO operation.

Within step 2, check whether you are recreating objects in your loop as this could be causing the issue rather than the IO.

Decide an actual time threshold that you want to warn about rather than a percentage of the last run - what happens if loop is 24% slowly than the previous one - this would compound up pretty quickly. I would suggest that you use the StopWatch[^] class for this - remember to reset the clock after each file though!

Once you have decided on you threashold time and a run through the loop exceeds this just log the filename as you are now.
Kenji Elzerman 22-Nov-11 4:41am
Hi Reiss,

I have used to stopwatch, but it was not accurate enough. I tested this with the same file, 4 times. First time was 0,01 ms, second time also, third time was 0,51 ms and the fourth time was 0,1 ms. You see my point?
I guess the third time my laptop was busy, so the application had a hickup?


This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900