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

Calculate processing time.

Hello,

I do:

Debug.WriteLine("A: " & DateTime.Now.Ticks.ToString)
REM Calculate a bunch of stuff. Some loops and math functions.
Debug.WriteLine("B: " & DateTime.Now.Ticks.ToString)

but both A and B have the exact the same value. Is this method incorrect?
When I make the function wait for 1 millisecond, A en B differ. Is there
another way to calculate the processing time? Without looping the stuff a
100 times and then devide the result by 100.

Thanks.
Dec 12 '05 #1
4 6209
>
Debug.WriteLine("A: " & DateTime.Now.Ticks.ToString)
REM Calculate a bunch of stuff. Some loops and math functions.
Debug.WriteLine("B: " & DateTime.Now.Ticks.ToString)

but both A and B have the exact the same value. Is this method incorrect?
When I make the function wait for 1 millisecond, A en B differ. Is there
another way to calculate the processing time? Without looping the stuff a
100 times and then devide the result by 100.


I would prefer doing it 100 or even more times, to make sure you get an
accurate timing.

The first time you run a routine the CLR might do some optimizing that
actually makes it run slower the first few times.

/Søren Reinke
Dec 12 '05 #2
"Qwert" <no**@nosp.com> schrieb
Hello,

I do:

Debug.WriteLine("A: " & DateTime.Now.Ticks.ToString)
REM Calculate a bunch of stuff. Some loops and math functions.
Debug.WriteLine("B: " & DateTime.Now.Ticks.ToString)

but both A and B have the exact the same value. Is this method
incorrect? When I make the function wait for 1 millisecond, A en B
differ. Is there another way to calculate the processing time?
Without looping the stuff a 100 times and then devide the result by
100.

In addition to Søren, the resolution of DateTime.Now is too low to measure
things. Use Environment.Tickcount (returns milliseconds) instead or a high
performance counter (in VB 2005, you can use System.Diagnostics.Stopwatch)

See also:
http://groups.google.com/group/micro...7a1a5c8d980072

(especially post #4ff ;-)

Armin

Dec 12 '05 #3
"Qwert" <no**@nosp.com> schrieb:
Debug.WriteLine("A: " & DateTime.Now.Ticks.ToString)
REM Calculate a bunch of stuff. Some loops and math functions.
Debug.WriteLine("B: " & DateTime.Now.Ticks.ToString)

but both A and B have the exact the same value. Is this method incorrect?


You may want to use this timer:

<URL:http://www.mentalis.org/soft/class.qpx?id=8>

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Dec 12 '05 #4
Great, thanks all.

That 'QueryPerformanceCounter' and 'QueryPerformanceFrequency' code of
mentalis did the trick. None of the .NET functionality I could find was
precise enough (fastest time was 0,0003 seconds).

Don't have VB2005 yet, so I couldn't try "in VB 2005, you can use
System.Diagnostics.Stopwatch". I did try:

Dim objProcessorTime As New System.Diagnostics.PerformanceCounter()
objProcessorTime.CategoryName = "Processor"
objProcessorTime.CounterName = "% Processor Time"
objProcessorTime.InstanceName = "_Total"

but wasn't precise enough.

"Herfried K. Wagner [MVP]" <hi***************@gmx.at> schreef in bericht
news:OI**************@tk2msftngp13.phx.gbl...
"Qwert" <no**@nosp.com> schrieb:
Debug.WriteLine("A: " & DateTime.Now.Ticks.ToString)
REM Calculate a bunch of stuff. Some loops and math functions.
Debug.WriteLine("B: " & DateTime.Now.Ticks.ToString)

but both A and B have the exact the same value. Is this method incorrect?


You may want to use this timer:

<URL:http://www.mentalis.org/soft/class.qpx?id=8>

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Dec 12 '05 #5

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

Similar topics

53
by: Cardman | last post by:
Greetings, I am trying to solve a problem that has been inflicting my self created Order Forms for a long time, where the problem is that as I cannot reproduce this error myself, then it is...
1
by: sg_s123 | last post by:
============================================================================ 02-Feb-04 03-Feb-04 Staff Staff 0800hr- 1300hr- 1700hr- 1900hr- 0800hr- 1300hr- 1700hr- 1900hr- Number...
7
by: Tim Quon | last post by:
Hi Is there any function to get the current time so I can calculate the execution time of my code? What all is in the time.h and sys/times.h? Thanks Tim
6
by: James Radke | last post by:
Hello, I have a multithreaded windows NT service application (vb.net 2003) that I am working on (my first one), which reads a message queue and creates multiple threads to perform the processing...
5
by: cvisal | last post by:
Hi all Im working on productivity calculations (Time calculations) and need some help in coding. Database Tool:MS-Access 2003. The general operator punch-in time is 5:30 AM and the punch-out...
2
by: cylin | last post by:
Hi, I am currently doing a project regarding image processing. I had facing problem writing C++ code to calculate time taken to execute a function. Can somebody help me on this. thanks. ...
4
by: NormAmst | last post by:
I have a list of CPU processing times and job durations for an entire department at work. There are 3 classifications I am maintaining. CPU time during peak hours , CPU time during non peak hours...
2
by: Lancelot | last post by:
Hello everyone. This is my first post here, but I've been looking for answer many time. I have a crazy idea in my head and since I am quite a newby to python, I am not sure where to start or if...
6
by: rrstudio2 | last post by:
I am using the following vba code to calculate the median of a table in MS Access: Public Function MedianOfRst(RstName As String, fldName As String) As Double 'This function will calculate the...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
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
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
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,...

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.