473,404 Members | 2,187 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,404 software developers and data experts.

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

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
Oct 19 '05 #1
2 2384
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);

}

KK wrote:
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

Oct 19 '05 #2
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

"KK" <KK.kk.com> wrote in message
news:uK**************@TK2MSFTNGP12.phx.gbl...
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

Oct 19 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: ThunderMusic | last post by:
Hi, I'm using the timespan's Parse method to build my timespan from a string. here's the line I use : m_Delay.Parse(RegKey.GetValue("Delay", "01:00:00")) the value I get from the RegKey is...
1
by: Rosanne | last post by:
I'm sure there's an easy solution to this that I am just not thinkin of. I am trying to get the total minutes between 2 times. It work fine except when the ending time crosses over midnight. For...
5
by: Larry Bird | last post by:
I want to use TimeSpan to determine the differences between two date to include time. My input data is in the following format: 12/25/2004 12:23:00 AM or 01/05/2005 11:59:00 PM How do I get...
2
by: DWalker | last post by:
In Visual Studio (Visual Basic) .NET 2002, I noticed that this: Dim Elapsed as DateTime = Now - Now gives a "compile time" error (error in the IDE), saying that the '-' operator is not...
2
by: KK | last post by:
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 -...
13
by: sd00 | last post by:
Hi all, can someone give me some coding help with a problem that *should* be really simple, yet I'm struggling with. I need the difference between 2 times (Target / Actual) However, these times...
3
by: Rob Meade | last post by:
Hi all, I'm having a bit of trouble with the following function.... Private Function GetSystemUpTime() As TimeSpan ' declare variables Dim Result As TimeSpan Dim PerformanceCounter As...
5
by: Vibhesh | last post by:
I am facing problem with TimeSpan structure when DirectX is used. Following is the sample code that causes the problem: ...
2
by: shapper | last post by:
Hello, I have the following: boxStat = new BoxStat { BoxCount = database.Boxes.Count(), SinceLastCreate = (DateTime.Now - database.Boxes.Max(b => b.CreatedAt)).Days ?? 0 };
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.