c# - .NET's Stopwatch Class, behaves strange -
so, have search algorithms, , sending random 20000 numbers each algorithm, trying figure out how long each take.
public void functionsforsorts(int[] array) { stopwatch sw = new stopwatch(); long elapsedtime = sw.elapsedticks; if (array.length == 20000) { sw.start(); bubblesort.bubble(array); sw.stop(); elapsedtime = sw.elapsedmilliseconds; label1.text += "\t" + elapsedtime.tostring() + " miliseconds "; application.doevents(); sw.restart(); selectionsort.selection(array); sw.stop(); elapsedtime = sw.elapsedmilliseconds; label2.text += "\t" + elapsedtime.tostring() + " miliseconds "; application.doevents(); sw.restart(); insertionsort.insertion(array); sw.stop(); elapsedtime = sw.elapsedmilliseconds; label3.text += "\t" + elapsedtime.tostring() + " miliseconds "; application.doevents(); sw.restart(); mergesort.mergesort(array, 0, array.length - 1); sw.stop(); elapsedtime = sw.elapsedmilliseconds; label4.text += "\t" + elapsedtime.tostring() + " miliseconds "; application.doevents(); sw.restart(); shellsort.shell(array); sw.stop(); elapsedtime = sw.elapsedmilliseconds; label5.text += "\t" + elapsedtime.tostring() + " miliseconds "; application.doevents(); sw.restart(); quicksort.quicksort(array, 0, array.length - 1); sw.stop(); elapsedtime = sw.elapsedmilliseconds; label6.text += "\t" + elapsedtime.tostring() + " miliseconds "; application.doevents(); }
the problem stopwatch won't give proper results, works ok bubble sort, selection sort , merge sort, don't know why, writes 0 insertionsort, though has proper value while debugging.and doesnt give proper values shell sort , quick sort too.
another awkward part this, when comment out bubble , selection sort, insertion give proper results, true algorithms, if make them 1st 1 in order, im getting proper results, showed friends, don't have clue either, doesn't make sense @ all...
if array sorted, it's possible insertion sort had nothing , finished in less 1 millisecond. possible if previous sort left array sorted.
(edit - apparently have hard time typing word "possible" instead of "possibly"... corrected.)
Comments
Post a Comment