473,396 Members | 1,827 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,396 software developers and data experts.

Calculating Time differences in milliseconds

Howdy,

I have looked and don't see a straight forward way to calculate time
differences in milliseconds.

What I am wanting to do is benchmark or time how long things take. So
I want to record the time ... do something ... record the time and see
how long the "do something" took.

Am I just being hairbrained here and its right in front of me or what?

Thanks

dbl

Nov 16 '05 #1
3 14591
DBLWizard,

Basically, when you want to find out how long something takes, store the
value of DateTime.Now in a variable, and then at the end of the operation,
subtract that from the current DateTime.Now value. This will give you a
TimeSpan instance from which you can find out how many milliseconds have
elapsed.

In .NET 2.0, you will want to use the Stopwatch class (I believe it is
in System.Diagnostics), as it will use the performance counter and give you
much more accurate results (as well as finer resolution, should you need
it).

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"DBLWizard" <ib*********@yahoo.com> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.com...
Howdy,

I have looked and don't see a straight forward way to calculate time
differences in milliseconds.

What I am wanting to do is benchmark or time how long things take. So
I want to record the time ... do something ... record the time and see
how long the "do something" took.

Am I just being hairbrained here and its right in front of me or what?

Thanks

dbl

Nov 16 '05 #2
DateTime start = DateTime.Now;
......
......
DateTime finish = DateTime.Now;
System.TimeSpan diff = finish - start;

string milliseconds = diff.TotalMilliseconds.ToString();
--
HTH

Ollie Riches
http://www.phoneanalyser.net

Disclaimer: Opinions expressed in this forum are my own, and not
representative of my employer.
I do not answer questions on behalf of my employer. I'm just a programmer
helping programmers.

"DBLWizard" <ib*********@yahoo.com> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.com...
Howdy,

I have looked and don't see a straight forward way to calculate time
differences in milliseconds.

What I am wanting to do is benchmark or time how long things take. So
I want to record the time ... do something ... record the time and see
how long the "do something" took.

Am I just being hairbrained here and its right in front of me or what?

Thanks

dbl

Nov 16 '05 #3
dbl,
It is right in front of you ;)
The difference between two DateTimes gives you a Timespan object.
The Timespan object has a "TotalMilliseconds" property.

:)
Andrew Arace

"DBLWizard" wrote:
Howdy,

I have looked and don't see a straight forward way to calculate time
differences in milliseconds.

What I am wanting to do is benchmark or time how long things take. So
I want to record the time ... do something ... record the time and see
how long the "do something" took.

Am I just being hairbrained here and its right in front of me or what?

Thanks

dbl

Nov 16 '05 #4

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

Similar topics

10
by: Andreas | last post by:
Hi! Is it possible to get a time event at a specific time, for instance eight a'clock? My program is running in the background and is minimized to the tray bar. If not, is there a smooth way...
1
by: Tony Williams | last post by:
I have a table with two fields, txtvalue (a number field) and txtmonth ( a date/time field). I want to create a report that shows the difference in value between the value in txtvalue in one value...
26
by: Pravesh | last post by:
Hi: is there a way to get current system time in milliseconds... which functions and headers?? thanks pravesh
5
by: Carlos | last post by:
Hi all, I have used the datetime class, but I just came up with a situation that need to have some advise. If I now how much time have passed, can I know the original date?. Lets say that I know...
9
by: HL | last post by:
I am using VS 2005 Beta - C# Problem: The Timer fires a few milliseconds before the actual Due-Time Let's say a timer is created in the following manner: System.Threading.Timer m_timer = null;...
74
by: Dominik Wallner | last post by:
Hi! I'm currently implementing a program which measures voltages through an external USB-AD-converter. It should output those values as time/voltage pairs. My problem is to measure the time...
2
by: Harlin Seritt | last post by:
How can I take a time given in milliseconds (I am doing this for an uptime script) and convert it to human-friendly time i.e. "4 days, 2 hours, 25 minutes, 10 seonds."? Is there a function from the...
9
by: Ron Adam | last post by:
I'm having some cross platform issues with timing loops. It seems time.time is better for some computers/platforms and time.clock others, but it's not always clear which, so I came up with the...
1
by: ndedhia1 | last post by:
I was reading in a log file like this that had no milliseconds: QuoteBlockTiming exceeded 1 ms: 1 --- Thu Dec 10 02:01:40 CST 2009 170.137.15.155 Class key = 601650761 block size QuoteBlockTiming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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,...
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
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...
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.