Click here to Skip to main content
15,888,002 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
How can I create Stopwatch for Measuring time of sorting?
Does it need another thread?

EDIT: OP wants to show the elapsed time of a sorting operation while it runs.
I need stopwatch like this:
http://www.keithv.com/software/stopwatch/stopwatch.zip[^]

when I press sort button, timer starts and when sorting operation complete the timer stops

also I use this code but it shows time when sorting is finished I need something show time from beginning to end
Stopwatch sw = Stopwatch.StartNew();
sw.Start();

// something happen

sw.Stop();
Posted
Updated 26-May-11 19:20pm
v4
Comments
Sandeep Mewara 26-May-11 10:48am    
Measuring time of sorting
What is it?
Member 7904482 26-May-11 10:58am    
I mean show time of sorting by stop watch
Marc A. Brown 26-May-11 11:11am    
Do you mean that you're trying to determine how much time a sorting operation takes overall? Or do you mean that you need to show the elapsed time for a sorting operation as it runs? Or something else entirely? Please clarify.
Member 7904482 26-May-11 11:21am    
I need to show the elapsed time for a sorting operation as it runs
S Houghtelin 27-May-11 9:38am    
Be aware that the process of measuring the time of each loop and displaying the time for each loop will prbably use more time than the operation you are timing. :/

This will provide erroneous timing results.

If you mean using the stopwatch class, here is a short tutorial.
http://www.dijksterhuis.org/timing-function-performance-stopwatch-class/[^]

Added by mab: Here's[^] the class info for Stopwatch.
 
Share this answer
 
v2
Comments
Marc A. Brown 26-May-11 11:28am    
Good answer.
S Houghtelin 26-May-11 11:32am    
Thanks :) and I did neglect to add the MSDN link.
Sergey Alexandrovich Kryukov 26-May-11 21:29pm    
All correct. This class is the right one for measurements. My 5.
--SA
S Houghtelin 27-May-11 9:34am    
Thanks :) I'll return the favor.
Sergey Alexandrovich Kryukov 28-May-11 3:33am    
...only if you find my answer correct or good. :-)
--SA
Here is another link that might help you[^].
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 26-May-11 21:32pm    
It works but MSDN is better; I checked up -- it explains everything. 5 anyway.
--SA
Abhinav S 27-May-11 0:20am    
Thank you SA.

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