473,394 Members | 2,168 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,394 software developers and data experts.

HOWTO - measure a function execution

I need to measure how long a function take to execute... or a sequence of
code within

--
Ceers,
Crirus

------------------------------
If work were a good thing, the boss would take it all from you

------------------------------
Nov 20 '05 #1
12 1599
Here is one 'CLUNKY' but probably fairly accurate way if the code execution
time is very small.

PSEUDO CODE
------------------

Dim startTime, EndTime as Time
Dim x as long
Const NTIMES = 10,000 ( Depending on the length of time to perform the
function )

startTime= Now
For x=1 to NTIMES ( Depending on the length of time to perform the
unction )

Call Function

Next
EndTime= now

Display "Time to run function = " & endTime-StartTime( In Seconds ) /
NTIMES
OHM

Crirus wrote:
I need to measure how long a function take to execute... or a
sequence of code within

Nov 20 '05 #2
Cor
Hi Crirus,

This one I copied once from Nick (Nak)

Dim StartTick As Integer = Environment.TickCount
.................
Dim Elapsed As Integer = Environment.TickCount - StartTick

Cor
Nov 20 '05 #3
"Crirus" <Cr****@datagroup.ro> schrieb
I need to measure how long a function take to execute... or a
sequence of code within


You can use
Environment.Tickcount
--
Armin

http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html

Nov 20 '05 #4
Where I got 0 as the time elapsed what does that mean.. is lightning fast?:)

--
Ceers,
Crirus

------------------------------
If work were a good thing, the boss would take it all from you

------------------------------

"Cor" <no*@non.com> wrote in message
news:ej**************@TK2MSFTNGP12.phx.gbl...
Hi Crirus,

This one I copied once from Nick (Nak)

Dim StartTick As Integer = Environment.TickCount
.................
Dim Elapsed As Integer = Environment.TickCount - StartTick

Cor

Nov 20 '05 #5
Cor
Yes most things are not to measure and you have to put them in a loop
Nov 20 '05 #6
Well, I'm concerning with the ones that give me 100 ticks :)

--
Ceers,
Crirus

------------------------------
If work were a good thing, the boss would take it all from you

------------------------------

"Cor" <no*@non.com> wrote in message
news:eh**************@TK2MSFTNGP11.phx.gbl...
Yes most things are not to measure and you have to put them in a loop

Nov 20 '05 #7
I found this
sometime next statement take 0 tick and sometime take 16 ticks...why's that?

TileImage = New Bitmap(imgTranz(trans(x, i, j) - 1, x - 1))

imgTranz is an array of images 14x8
trans is an array of integers from 1 to 15

--
Ceers,
Crirus

------------------------------
If work were a good thing, the boss would take it all from you

------------------------------

"Cor" <no*@non.com> wrote in message
news:eh**************@TK2MSFTNGP11.phx.gbl...
Yes most things are not to measure and you have to put them in a loop

Nov 20 '05 #8
For all sorts of reasons, like the machine may be busy doing other things at
the time. Thats why I suggested that you call the function over a period of
time ( thousands of calls ) then you can get the average.

But no one listens to me, perhaps I should stop posting.

OHM
Crirus wrote:
I found this
sometime next statement take 0 tick and sometime take 16
ticks...why's that?

TileImage = New Bitmap(imgTranz(trans(x, i, j) - 1, x - 1))

imgTranz is an array of images 14x8
trans is an array of integers from 1 to 15
"Cor" <no*@non.com> wrote in message
news:eh**************@TK2MSFTNGP11.phx.gbl...
Yes most things are not to measure and you have to put them in a loop

Nov 20 '05 #9

"One Handed Man" <Bo****@Duck.net> wrote in message
news:bp**********@titan.btinternet.com...
<SNIP>

OHM is on the ball. Windows is finicky, and even if you don't have
another program running, it's always doing something. And remember, a CPU
can only handle 1 function at a time, that's why cache was invented, so
doing a bench-mark twice is not going to do anything but upset you because
it may run a 0 ticks if nothing else is going on, or 16 ticks if it had to
wait for another process so it could execute a call.
Run it 100 times, each time writing the resaults to a file, call a
System.Threading.Thread.Sleep(5000) between each execution of the loop. It
will take 500,000 ms (about 8 1/2 minutes) to finish the benchmark, but you
will have a very accurate set of numbers. The simply open the file into
Excel or something similar, and get the average, and there is your ART
(Average RunTime) for the function. Use that number for stateting how fast
the function runs.

HTH
Suefell
---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.538 / Virus Database: 333 - Release Date: 11/10/2003
Nov 20 '05 #10
Suffel,

Thank You!

OHM

---------------------------------------------------
Sueffel wrote:
"One Handed Man" <Bo****@Duck.net> wrote in message
news:bp**********@titan.btinternet.com...
<SNIP>

OHM is on the ball. Windows is finicky, and even if you don't
have another program running, it's always doing something. And
remember, a CPU can only handle 1 function at a time, that's why
cache was invented, so doing a bench-mark twice is not going to do
anything but upset you because it may run a 0 ticks if nothing else
is going on, or 16 ticks if it had to wait for another process so it
could execute a call. Run it 100 times, each time writing the
resaults to a file, call a System.Threading.Thread.Sleep(5000)
between each execution of the loop. It will take 500,000 ms (about 8
1/2 minutes) to finish the benchmark, but you will have a very
accurate set of numbers. The simply open the file into Excel or
something similar, and get the average, and there is your ART
(Average RunTime) for the function. Use that number for stateting
how fast the function runs.

HTH
Suefell
---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.538 / Virus Database: 333 - Release Date: 11/10/2003

Nov 20 '05 #11
* "Crirus" <Cr****@datagroup.ro> scripsit:
I need to measure how long a function take to execute... or a sequence of
code within


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

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>
Nov 20 '05 #12
In addition, timer resolution is only good for about 15 ticks anyway, so a
method that takes 8 ticks to execute may actually just return 0.

-- russ

"Crirus" <Cr****@datagroup.ro> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
I found this
sometime next statement take 0 tick and sometime take 16 ticks...why's that?
TileImage = New Bitmap(imgTranz(trans(x, i, j) - 1, x - 1))

imgTranz is an array of images 14x8
trans is an array of integers from 1 to 15

--
Ceers,
Crirus

------------------------------
If work were a good thing, the boss would take it all from you

------------------------------

"Cor" <no*@non.com> wrote in message
news:eh**************@TK2MSFTNGP11.phx.gbl...
Yes most things are not to measure and you have to put them in a loop


Nov 20 '05 #13

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

Similar topics

15
by: Bob | last post by:
I've tried everything; and I can't seem to get past this VERY (seemingly) simply problem. I want to work with an array variable within a function(s). I can't get it to work; if I: 1) global...
3
by: domeceo | last post by:
can anyone tell me why I cannot pass values in a setTimeout function whenever I use this function it says "menu is undefined" after th alert. function imgOff(menu, num) { if (document.images) {...
5
by: Erwin Kloibhofer | last post by:
what if i have a webpage that displays the text "please wait, this may take a few seconds..." and it now waits until some event on the server happens. whatever this is, this can be quick, but it...
6
by: cranium.2003 | last post by:
hello, If i wrote a C function then how to know that its costlier in terms of processing time,execution,compilation. I have written 2 functions for one problem but dont understand which one is...
4
by: Ray Dukes | last post by:
What I am looking to do is map the implementation of interface properties and functions to an inherited method of the base class. Please see below. ...
13
by: Sharon | last post by:
I need to test a performance of some code of mine. I tried using the Environment.TickCount but its resolution is too low (from the MSDN remarks: The resolution of the TickCount property cannot be...
15
by: Frank | last post by:
Before I start, please let's not discuss whether goto is evil or not. For generated code, this can make perfect sense. It would be interesting to know a trick how to get C to do a goto to an...
1
by: Dijkstra | last post by:
On 9 jul, 15:16, "gautamcoo...@gmail.com" <gautamcoo...@gmail.com> wrote: The compiler does not "execute" nothing. But I understand what you mean. The compiler only optimizes what it can see...
7
by: Peted | last post by:
Hi, im hoping someone cane provide or point to a definitive accurate explantion of dotnet compilation when run and the best way to optimise peformace when dotnet code is run first time and...
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
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: 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
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,...
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...

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.