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

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
 
J

jeremiah johnson

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);

}
 
S

Scott Coonce

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top