473,802 Members | 2,213 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

TimeSpan(startT icks - EndTicks).Total Miliseconds returns 0 ???

KK
Hi

I was testing a quicksort algorithm.

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

q_sort( 0, mElements.Lengt h-1 );

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

mSortTime = tp.TotalMillise conds; //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 2420
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(10 0); //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.WriteLi ne(mSortTime);

}

KK wrote:
Hi

I was testing a quicksort algorithm.

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

q_sort( 0, mElements.Lengt h-1 );

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

mSortTime = tp.TotalMillise conds; //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((DateT ime.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******** ******@TK2MSFTN GP12.phx.gbl...
Hi

I was testing a quicksort algorithm.

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

q_sort( 0, mElements.Lengt h-1 );

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

mSortTime = tp.TotalMillise conds; //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
3181
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 00:00:30, so it should give a timespan of 30 seconds, but when I do msgbox(m_Delay.ToString), it displays 00:00:00. Am I doing something wrong?
1
1383
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 instance I am trying to get the total minutes between 11:59 PM and 12:09 AM. The subtract method on the TimeSpan object returns a crazy negativ number. I can't seem to find a work around. Thanks so much in advance! --
5
11520
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 TimeSpan to accept my input? How do I get the difference between two dates using TimeSpan? I want to have the results expressed in days, hours, minutes and seconds.
2
19137
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 defined for the Date datatype. On the other hand, Dim Elapsed as DateTime = Now + Now does not give a compile time error but it thinks you're trying to
2
346
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 - startTime)); //difference of ticks
13
2153
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 will fall somewhere between a Start & End time Further more, there will be Break & Lunch times between Start & End. Example... Start 08:00 Break start 10:30
3
2891
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 PerformanceCounter
5
2008
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: *************************************************************************************************************** { ........................... PrintTimeSpanProblem(); device = new Device(0, DeviceType.Hardware, this, CreateFlags.SoftwareVertexProcessing, presentParams); PrintTimeSpanProblem();
2
12643
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
9699
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10536
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10304
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10285
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9114
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6838
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
4270
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3792
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2966
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.