question one: the last few days to write the actual application of parallel computing-the Address book, the use of stopwatch to time, found that the timing is the real timing.
Stopwatch Stopwatch =NewStopwatch (); TimeSpan TimeSpan; Doubletime1,time2; Stopwatch. Start (); F1 ();//Take time T1stopwatch. Stop (); TimeSpan=stopwatch. Elapsed; Time1= Timespan.totalmilliseconds;//time1=t1stopwatch. Start (); F2 ();//Take time T2stopwatch. Stop (); TimeSpan=stopwatch. Elapsed; Time2= Timespan.totalmilliseconds;//Time2=t1+t2
The time of Time2 is t1+t2, which is different from the tim2=t2 I expected ...
Workaround:
1. Use different timers stopwatch and STOPWATCH2, such as code:
Stopwatch Stopwatch =NewStopwatch (); Stopwatch STOPWATCH2=NewStopwatch (); TimeSpan TimeSpan; Doubletime1,time2; Stopwatch. Start (); F1 ();//Take time T1stopwatch. Stop (); TimeSpan=stopwatch. Elapsed; Time1= Timespan.totalmilliseconds;//time1=t1STOPWATCH2. Start (); F2 ();//Take time T2STOPWATCH2. Stop (); TimeSpan=STOPWATCH2. Elapsed; Time2= Timespan.totalmilliseconds;//Time2=t2
2. Using the Reset function to empty the timer stopwatch is also easy to understand, code slightly.
question two: See code:
Stopwatch Stopwatch =NewStopwatch (); Stopwatch STOPWATCH2=NewStopwatch (); TimeSpan TimeSpan; Doubletime1,time2; Stopwatch. Start (); F1 ();//Take time T1stopwatch. Stop (); TimeSpan=stopwatch. Elapsed; Time1= Timespan.totalmilliseconds;//time1=t1STOPWATCH2. Start (); F2 ();//Take time T2
Stopwatch. Stop ();//The STOPWATCH2 should be here. Stop ();
TimeSpan =STOPWATCH2. Elapsed; Time2= Timespan.totalmilliseconds;//Time2=t2
At the end of the second timer STOPWATCH2, Stopwatch2 knocked into the stopwatch, then the problem came, my program has not been affected ...
The reason is that you can query the run time properties when the stopwatch instance is running or stopped.
That's the sentence, that is to say
Although STOPWATCH2 does not have a stop, the sentence in my code is TimeSpan = stopwatch2. Elapsed; The current recorded time is extracted ...
So the time I recorded was not affected, that is, Time1=t1, Time2=t2.
C # Stopwatch