TimeSpan(startTicks - EndTicks).TotalMiliseconds returns 0 ???

  • Thread starter Thread starter KK
  • Start date Start date
K

KK

Hi

I was testing a quicksort algorithm.

long startTime = DateTime.Now.Ticks; //ticks before sorting begins

q_sort( 0, mElements.Length-1 );

TimeSpan tp =new TimeSpan((DateTime.Now.Ticks - startTime)); //difference of
ticks

mSortTime = tp.TotalMilliseconds; //sort time in milliseconds

Still, it alwasy returns 0.0

But other algorithms returns a valid value.

However, there is a positive difference between the ticks too.

I can't understand why it is behaving like this. Btw, sorting
works in a different thread.

Any insight?

rgds
KK
 
your code worked fine for me, but i rewrote it for clarity.

static void Main(string[] args) {

DateTime startTime = DateTime.Now; //before sorting begins
Thread.Sleep(100); //simulate the sort
DateTime endTime = DateTime.Now; //after the sort

TimeSpan ts = endTime - startTime; //time difference

double mSortTime = ts.Milliseconds; //sort time in milliseconds

Console.WriteLine(mSortTime);

}
 
Umm, maybe this is either too obvious, or I'm wrong, but at the end of the
OP, KK said the sort runs in a different thread... Maybe

TimeSpan tp =new TimeSpan((DateTime.Now.Ticks - startTime));

is called before the sorting actually starts in the *other* thread?

Just an idea,
Scott
 
Back
Top