Hi,
Im trying to time some parts of my code using the Stopwatch class,
but it is so slow, I tried the QueryPerformanc eFrequency()
but this seems to be just as slow,
if I just simply call this function in a loop it takes 21 ticks
with a reported frequency of 3.5mhz
its is about 6us wich is over 12k instructions on my 2ghz cpu.
this negates the idea of having a high res timer ...
Is there any way to access the timer more directly ?
I know the cpu actually has a very high resolution timer,
it would be nice to be able to just read this value directly,
maybe il have to write a c++ library and do it in asm
thats assuming I can get the OS to grant me acces to that hardware address.
basicaly im making a diy profiler, I have a profile class
wich needs Enter(enum p) funtion at the start and a Leave()
function at the end of some functions of interest.
primarily it keeps tarck of the number of calls made,
and a lists the calling functions counts too.
it also measures the total time spent in the function and the subtracts the
time spent in
subroutins to provide an actual time too.
It works pretty quick for counts but when I use the timer it is like 20
times slower,
wich although I can live with waiting 20 minutes to collect the data it does
mean
that there is a considerable error for short functions,
I have added a fudge wich subtracts a fiddle value from the timer,
wich is increased by 21 ticks every times its called,
this might be close but its far from ideal.
Im trying to find out why/where its spending 75% of the cpu time in
mscorlib and mscorwks libraries, the amd codeanalyst identifies its spending
most of its time in a function called mscorwks::gc_he ap::adjust_limi t_clr
thanks
Colin =^.^= 19 5208
"colin" <co*********@nt world.NOSPAM.co mwrote in message
news:kr******** ******@newsfe4-win.ntli.net...
Hi,
Im trying to time some parts of my code using the Stopwatch class,
but it is so slow, I tried the QueryPerformanc eFrequency()
but this seems to be just as slow,
if I just simply call this function in a loop it takes 21 ticks
with a reported frequency of 3.5mhz
its is about 6us wich is over 12k instructions on my 2ghz cpu.
this negates the idea of having a high res timer ...
Is there any way to access the timer more directly ?
I know the cpu actually has a very high resolution timer,
it would be nice to be able to just read this value directly,
maybe il have to write a c++ library and do it in asm
thats assuming I can get the OS to grant me acces to that hardware
address.
basicaly im making a diy profiler, I have a profile class
wich needs Enter(enum p) funtion at the start and a Leave()
function at the end of some functions of interest.
primarily it keeps tarck of the number of calls made,
and a lists the calling functions counts too.
it also measures the total time spent in the function and the subtracts
the time spent in
subroutins to provide an actual time too.
It works pretty quick for counts but when I use the timer it is like 20
times slower,
wich although I can live with waiting 20 minutes to collect the data it
does mean
that there is a considerable error for short functions,
I have added a fudge wich subtracts a fiddle value from the timer,
wich is increased by 21 ticks every times its called,
this might be close but its far from ideal.
Im trying to find out why/where its spending 75% of the cpu time in
mscorlib and mscorwks libraries, the amd codeanalyst identifies its
spending
most of its time in a function called mscorwks::gc_he ap::adjust_limi t_clr
thanks
Colin =^.^=
Please post your code, there must be something wrong with it,
QueryPerformanc eFrequency()
can't take 6µsec to complete.
Note that there is no need to call QueryPerformanc eFrequency(), this value
exposed by the Stopwatch class.
Willy.
I just copied the code from here http://msdn2.microsoft.com/en-us/lib...92(VS.80).aspx
and oops I meant the QueryPerformanc eCounter() call is taking so long ...
I just have a loop wich calls it repeatedly 100000 times to measure how long
it takes.
the Stopwatch also took just as long.
Colin =^.^=
>
Please post your code, there must be something wrong with it,
QueryPerformanc eFrequency()
can't take 6µsec to complete.
Note that there is no need to call QueryPerformanc eFrequency(), this value
exposed by the Stopwatch class.
Willy.
"Willy Denoyette [MVP]" <wi************ *@telenet.bewro te in message
news:ea******** ******@TK2MSFTN GP03.phx.gbl...
"colin" <co*********@nt world.NOSPAM.co mwrote in message
news:kr******** ******@newsfe4-win.ntli.net...
>Hi,
Im trying to time some parts of my code using the Stopwatch class, but it is so slow, I tried the QueryPerformanc eFrequency() but this seems to be just as slow, if I just simply call this function in a loop it takes 21 ticks with a reported frequency of 3.5mhz its is about 6us wich is over 12k instructions on my 2ghz cpu. this negates the idea of having a high res timer ...
Is there any way to access the timer more directly ? I know the cpu actually has a very high resolution timer, it would be nice to be able to just read this value directly, maybe il have to write a c++ library and do it in asm thats assuming I can get the OS to grant me acces to that hardware address.
basicaly im making a diy profiler, I have a profile class wich needs Enter(enum p) funtion at the start and a Leave() function at the end of some functions of interest.
primarily it keeps tarck of the number of calls made, and a lists the calling functions counts too. it also measures the total time spent in the function and the subtracts the time spent in subroutins to provide an actual time too.
It works pretty quick for counts but when I use the timer it is like 20 times slower, wich although I can live with waiting 20 minutes to collect the data it does mean that there is a considerable error for short functions,
I have added a fudge wich subtracts a fiddle value from the timer, wich is increased by 21 ticks every times its called, this might be close but its far from ideal.
Im trying to find out why/where its spending 75% of the cpu time in mscorlib and mscorwks libraries, the amd codeanalyst identifies its spending most of its time in a function called mscorwks::gc_he ap::adjust_limi t_clr
thanks Colin =^.^=
Please post your code, there must be something wrong with it,
QueryPerformanc eFrequency()
can't take 6µsec to complete.
Note that there is no need to call QueryPerformanc eFrequency(), this value
exposed by the Stopwatch class.
Willy.
Well, QueryPerformanc eFrequency must transition into the kernel, which is
quite expensive, (6000 instructions), so this function may well take +4
µsec on a 2Ghz machine. The same is true for QueryPerformanc eCounter, so you
need to account for this overhead when profiling.
Windows Vista and WS2008 have a new API QueryThreadCycl eTime which returns
the CPU cycles count.
This API calls the __rdtsc(); VC++ compilers intrinsic function, you can
implement a small C function that calls this intrinsic and call this one
from C# using PInvoke.
Willy.
"colin" <co*********@nt world.NOSPAM.co mwrote in message
news:SY******** ********@newsfe 1-win.ntli.net...
>I just copied the code from here http://msdn2.microsoft.com/en-us/lib...92(VS.80).aspx
and oops I meant the QueryPerformanc eCounter() call is taking so long ...
I just have a loop wich calls it repeatedly 100000 times to measure how
long it takes.
the Stopwatch also took just as long.
Hmmm.. this code is meant for the compact framework (WinCE).
The exact PInvoke declaration for Windows is:
[DllImport("kern el32"),Suppress UnmanagedCodeSe curity]
static extern int QueryPerformanc eFrequency(out long freq);
but as I said in another reply QueryPerformanc eFrequency is an expensive
call.
Willy.
"Willy Denoyette [MVP]" <wi************ *@telenet.bewro te in message
news:eA******** ******@TK2MSFTN GP03.phx.gbl...
"colin" <co*********@nt world.NOSPAM.co mwrote in message
news:SY******** ********@newsfe 1-win.ntli.net...
>>I just copied the code from here http://msdn2.microsoft.com/en-us/lib...92(VS.80).aspx
and oops I meant the QueryPerformanc eCounter() call is taking so long ...
I just have a loop wich calls it repeatedly 100000 times to measure how long it takes.
the Stopwatch also took just as long.
Hmmm.. this code is meant for the compact framework (WinCE).
The exact PInvoke declaration for Windows is:
[DllImport("kern el32"),Suppress UnmanagedCodeSe curity]
static extern int QueryPerformanc eFrequency(out long freq);
but as I said in another reply QueryPerformanc eFrequency is an expensive
call.
Ah yes i found that out after I copied it and had to go search for
coredll.dll
it seems its in kernel32 for non ce
I aded the supress security too
in the hope it might speed it up ...
seems these two calls are easy to mix up when writing them lol...
i just call frequency func once, and the counter func about 100million times
thanks
Colin =^.^=
"Willy Denoyette [MVP]" <wi************ *@telenet.bewro te in message
news:eM******** ******@TK2MSFTN GP05.phx.gbl...
"Willy Denoyette [MVP]" <wi************ *@telenet.bewro te in message
news:ea******** ******@TK2MSFTN GP03.phx.gbl...
>"colin" <co*********@nt world.NOSPAM.co mwrote in message news:kr******* *******@newsfe4-win.ntli.net...
>>Hi,
Im trying to time some parts of my code using the Stopwatch class, but it is so slow, I tried the QueryPerformanc eFrequency() but this seems to be just as slow, if I just simply call this function in a loop it takes 21 ticks with a reported frequency of 3.5mhz its is about 6us wich is over 12k instructions on my 2ghz cpu. this negates the idea of having a high res timer ...
Is there any way to access the timer more directly ? I know the cpu actually has a very high resolution timer, it would be nice to be able to just read this value directly, maybe il have to write a c++ library and do it in asm thats assuming I can get the OS to grant me acces to that hardware address.
basicaly im making a diy profiler, I have a profile class wich needs Enter(enum p) funtion at the start and a Leave() function at the end of some functions of interest.
primarily it keeps tarck of the number of calls made, and a lists the calling functions counts too. it also measures the total time spent in the function and the subtracts the time spent in subroutins to provide an actual time too.
It works pretty quick for counts but when I use the timer it is like 20 times slower, wich although I can live with waiting 20 minutes to collect the data it does mean that there is a considerable error for short functions,
I have added a fudge wich subtracts a fiddle value from the timer, wich is increased by 21 ticks every times its called, this might be close but its far from ideal.
Im trying to find out why/where its spending 75% of the cpu time in mscorlib and mscorwks libraries, the amd codeanalyst identifies its spending most of its time in a function called mscorwks::gc_ heap::adjust_li mit_clr
thanks Colin =^.^=
Please post your code, there must be something wrong with it, QueryPerforman ceFrequency() can't take 6µsec to complete. Note that there is no need to call QueryPerformanc eFrequency(), this value exposed by the Stopwatch class. Willy.
Well, QueryPerformanc eFrequency must transition into the kernel, which is
quite expensive, (6000 instructions), so this function may well take +4
µsec on a 2Ghz machine. The same is true for QueryPerformanc eCounter, so
you need to account for this overhead when profiling.
Windows Vista and WS2008 have a new API QueryThreadCycl eTime which returns
the CPU cycles count.
This API calls the __rdtsc(); VC++ compilers intrinsic function, you can
implement a small C function that calls this intrinsic and call this one
from C# using PInvoke.
Willy.
// C function that uses an intrinsic to retrieve the Processor's cycle
counter register
// Beware your CPU may not support this!
// Compile from the command line: cl /EHsc /O2 <thisfile.cpp >
#include <intrin.h>
#pragma intrinsic(__rdt sc)
extern "C"
__declspec(dlle xport) unsigned __int64 __stdcall rdtsc()
{
return __rdtsc();
}
// C#
[DllImport("this file.dll"),Supp ressUnmanagedCo deSecurity]
static extern ulong rdtsc();
...
ulong cycles = rdtsc();
Willy.
"Willy Denoyette [MVP]" <wi************ *@telenet.bewro te in message
news:%2******** ********@TK2MSF TNGP02.phx.gbl. ..
"Willy Denoyette [MVP]" <wi************ *@telenet.bewro te in message
// C function that uses an intrinsic to retrieve the Processor's cycle
counter register
// Beware your CPU may not support this!
// Compile from the command line: cl /EHsc /O2 <thisfile.cpp >
#include <intrin.h>
#pragma intrinsic(__rdt sc)
extern "C"
__declspec(dlle xport) unsigned __int64 __stdcall rdtsc()
{
return __rdtsc();
}
// C#
[DllImport("this file.dll"),Supp ressUnmanagedCo deSecurity]
static extern ulong rdtsc();
...
ulong cycles = rdtsc();
Willy.
thanks that worked, however it stil takes 9000 clock cycles
wich I think is roughly about the same time ...
is that PInvoke realy so time consuming ?
what does it have todo ?
thanks
Colin =^.^=
"colin" <co*********@nt world.NOSPAM.co mwrote in message
news:4J******** *******@newsfe6-win.ntli.net...
"Willy Denoyette [MVP]" <wi************ *@telenet.bewro te in message
news:%2******** ********@TK2MSF TNGP02.phx.gbl. ..
>"Willy Denoyette [MVP]" <wi************ *@telenet.bewro te in message
>// C function that uses an intrinsic to retrieve the Processor's cycle counter register // Beware your CPU may not support this! // Compile from the command line: cl /EHsc /O2 <thisfile.cpp > #include <intrin.h> #pragma intrinsic(__rdt sc) extern "C" __declspec(dll export) unsigned __int64 __stdcall rdtsc() { return __rdtsc(); }
// C# [DllImport("this file.dll"),Supp ressUnmanagedCo deSecurity] static extern ulong rdtsc();
... ulong cycles = rdtsc();
Willy.
thanks that worked, however it stil takes 9000 clock cycles
wich I think is roughly about the same time ...
is that PInvoke realy so time consuming ?
what does it have todo ?
Ive just used Environment.Tic kCount, its only 1ms resolution
but it seems to be instant.
as ive plenty enough samples it seems to give some results still ...
thanks
Colin =^.^=
"colin" <co*********@nt world.NOSPAM.co mwrote in message
news:D%******** *******@newsfe6-win.ntli.net...
"colin" <co*********@nt world.NOSPAM.co mwrote in message
news:4J******** *******@newsfe6-win.ntli.net...
>"Willy Denoyette [MVP]" <wi************ *@telenet.bewro te in message news:%2******* *********@TK2MS FTNGP02.phx.gbl ...
>>"Willy Denoyette [MVP]" <wi************ *@telenet.bewro te in message
>>// C function that uses an intrinsic to retrieve the Processor's cycle counter register // Beware your CPU may not support this! // Compile from the command line: cl /EHsc /O2 <thisfile.cpp > #include <intrin.h> #pragma intrinsic(__rdt sc) extern "C" __declspec(dl lexport) unsigned __int64 __stdcall rdtsc() { return __rdtsc(); }
// C# [DllImport("this file.dll"),Supp ressUnmanagedCo deSecurity] static extern ulong rdtsc();
... ulong cycles = rdtsc();
Willy.
thanks that worked, however it stil takes 9000 clock cycles wich I think is roughly about the same time ... is that PInvoke realy so time consuming ? what does it have todo ?
Ive just used Environment.Tic kCount, its only 1ms resolution
but it seems to be instant.
To do what?
Using TickCount to measure something that takes less that the RTC interval
will return the same count, the reason is that TickCount is updated at the
rithm of the system clock (every 10 or 15.6 msec. or more....).
Willy.
Willy.
Willy. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: ham-z |
last post by:
I have written the following Win app in VB.NET 2003 . The class is simply
picture boxes that behave in a random order after they have been
instantiated and added to a form. When I create 15 or more instances of my
class, the whole program runs slowly in a way that I have to close the
program. I have tried to create a new thread for each class, but that throws
an exception , because a separated thread can't be added to a form from a
child...
|
by: Michael Evans |
last post by:
First, we rely on a stable update rate so that our physics and dynamics
calculations and integrations are based on a known interval and
therefore are true-to-life.
Second, the graphics positions in our image generators are updated by
this dynamics application, and we need to update them at the rate they
are being refreshed so that we don't get any stutter from frames being
used twice or having to be thrown out.
Without microsecond...
|
by: Ty |
last post by:
I am developing a .net application using C# that requires a 1ms timer. I
have tried creating said timer by creating a timer object
(System.Timers.Timer) that is seeded with a 1ms interval. I have also tried
creating a thread with a 1ms sleep time.
The timer object that was created will only yield a resolution as low as
10ms no matter how low the interval is set.
Most of the time the thread timer yields the same 10ms resolution as the...
|
by: Extremest |
last post by:
I know there are ways to make this a lot faster. Any
newsreader does this in seconds. I don't know how they do
it and I am very new to c#. If anyone knows a faster way
please let me know. All I am doing is quering the db for
all the headers for a certain group and then going through
them to find all the parts of each post. I only want ones
that are complete. Meaning all segments for that one file
posted are there.
using System;
|
by: John |
last post by:
The table below shows the execution time for this code snippet as
measured by the unix command `time':
for i in range(1000):
time.sleep(inter)
inter execution time ideal
0 0.02 s 0 s
1e-4 4.29 s 0.1 s
1e-3 4.02 s 1 s
| |
by: arun thakur |
last post by:
hi all,
how could i get a millisecond resolution timer in linux platform with GPS input of 1 PPS .i want to use this timer for the synchronized the channel switching mechanism in wireless medium.
plz help!
thanx
|
by: ssecorp |
last post by:
I am not clear about the results here.
from timeit import Timer
import Decorators
def fib(n):
a, b = 1, 0
while n:
a, b, n = b, a+b, n-1
|
by: cnb |
last post by:
For a big nbr of it might matter?
Is av_grade O(n*2) and the first O(n) when it comes to adding or is
"sum x for x in y" just traversing the list ones, accumulating the
values, it doesnt first build the list and then travese it for sum?
def averageGrade(self):
tot = 0
for review in self.reviews:
tot += review.grade
return tot / len(self.reviews)
|
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...
|
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...
|
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
| |
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...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
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();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
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...
| |