Est ce que cette fonction est bonne ou bien il y a autres fonctions
qui nous donnent le temps pr=E9cis ni plus ni moins ?
j'obtiens un temps t diff=E9rent ou bien =E9gale =E0 chaque fois que je
lance l'ex=E9cution de plus il arrive que
t =3D0.000000 malgr=E9 que il existe un traitement.
et comment =E9viter d'obtenir un temps nul ?
> Voir la fonction DoBench() avec QueryPerformanceCounter() du vieil > article :http://msdn.microsoft.com/en-us/library/aa260969(VS.60).aspx
Mais, cette fonction utilise la fonction time() donc pourquoi pas on utilise directement time() ?
Hein ?!! Elle utilise QueryPerformanceCounter() !!!
programmation
On 10 sep, 15:52, Christian ASTOR wrote:
On 10 sep, 15:03, programmation wrote:
> > Voir la fonction DoBench() avec QueryPerformanceCounter() du vieil > > article :http://msdn.microsoft.com/en-us/library/aa260969(VS.60).aspx > Mais, cette fonction utilise la fonction time() donc pourquoi pas on > utilise directement time() ?
Hein ?!! Elle utilise QueryPerformanceCounter() !!!
Pouvez vous m'aider pour que je puisse utiliser cette fonction dans le programme car je n'arrive pas à l'exploiter ?
Merci.
On 10 sep, 15:52, Christian ASTOR <casto...@club-internet.fr> wrote:
On 10 sep, 15:03, programmation <bouali.a...@gmail.com> wrote:
> > Voir la fonction DoBench() avec QueryPerformanceCounter() du vieil
> > article :http://msdn.microsoft.com/en-us/library/aa260969(VS.60).aspx
> Mais, cette fonction utilise la fonction time() donc pourquoi pas on
> utilise directement time() ?
Hein ?!!
Elle utilise QueryPerformanceCounter() !!!
Pouvez vous m'aider pour que je puisse utiliser cette fonction dans le
programme car je n'arrive pas à l'exploiter ?
> > Voir la fonction DoBench() avec QueryPerformanceCounter() du vieil > > article :http://msdn.microsoft.com/en-us/library/aa260969(VS.60).aspx > Mais, cette fonction utilise la fonction time() donc pourquoi pas on > utilise directement time() ?
Hein ?!! Elle utilise QueryPerformanceCounter() !!!
Pouvez vous m'aider pour que je puisse utiliser cette fonction dans le programme car je n'arrive pas à l'exploiter ?
Merci.
programmation
On 10 sep, 21:09, programmation wrote:
On 10 sep, 15:52, Christian ASTOR wrote:
> On 10 sep, 15:03, programmation wrote:
> > > Voir la fonction DoBench() avec QueryPerformanceCounter() du vieil > > > article :http://msdn.microsoft.com/en-us/library/aa260969(VS.60).as px > > Mais, cette fonction utilise la fonction time() donc pourquoi pas on > > utilise directement time() ?
> Hein ?!! > Elle utilise QueryPerformanceCounter() !!!
Bonjour,
Voici le code que je trouve dans ce lien http://msdn.microsoft.com/en-us/library/aa260969(VS.60).aspx
#include "time.h"
enum { ttuUnknown, ttuHiRes, ttuClock } TimerToUse = ttuUnknown; LARGE_INTEGER PerfFreq; // ticks per second int PerfFreqAdjust; // in case Freq is too big int OverheadTicks; // overhead in calling timer
// Assume the worst TimerToUse = ttuClock; if ( QueryPerformanceFrequency(&PerfFreq) ) { // We can use hires timer, determine overhead TimerToUse = ttuHiRes; OverheadTicks = 200; for ( int i=0; i < 20; i++ ) { LARGE_INTEGER b,e; int Ticks; QueryPerformanceCounter(&b); (*pFunc)(); QueryPerformanceCounter(&e); Ticks = e.LowPart - b.LowPart; if ( Ticks >= 0 && Ticks < OverheadTicks ) OverheadTicks = Ticks; } // See if Freq fits in 32 bits; if not lose some precision PerfFreqAdjust = 0; int High32 = PerfFreq.HighPart; while ( High32 ) { High32 >>= 1; PerfFreqAdjust++; } } return; }
double DoBench(void(*funcp)()) { double time; /* Elapsed time */
// Let any other stuff happen before we start MSG msg; PeekMessage(&msg,NULL,NULL,NULL,PM_NOREMOVE); Sleep(0);
if ( TimerToUse == ttuUnknown ) DetermineTimer();
if ( TimerToUse == ttuHiRes ) { LARGE_INTEGER tStart, tStop; LARGE_INTEGER Freq = PerfFreq; int Oht = OverheadTicks; int ReduceMag = 0; SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_TIME_CRITICAL); QueryPerformanceCounter(&tStart); (*funcp)(); //call the actual function being timed QueryPerformanceCounter(&tStop); SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_NORMAL); // Results are 64 bits but we only do 32 unsigned int High32 = tStop.HighPart - tStart.HighPart; while ( High32 ) { High32 >>= 1; ReduceMag++; } if ( PerfFreqAdjust || ReduceMag ) { if ( PerfFreqAdjust > ReduceMag ) ReduceMag = PerfFreqAdjust; tStart.QuadPart = Int64ShrlMod32(tStart.QuadPart, ReduceMag); tStop.QuadPart = Int64ShrlMod32(tStop.QuadPart, ReduceMag); Freq.QuadPart = Int64ShrlMod32(Freq.QuadPart, ReduceMag); Oht >>= ReduceMag; }
// Reduced numbers to 32 bits, now can do the math if ( Freq.LowPart == 0 ) time = 0.0; else time = ((double)(tStop.LowPart - tStart.LowPart - Oht))/Freq.LowPart; } else { long stime, etime; SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_TIME_CRITICAL); stime = clock(); (*funcp)(); etime = clock(); SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_NORMAL); time = ((double)(etime - stime)) / CLOCKS_PER_SEC; }
return (time); }
dans ce code il y a les fonctions comme "QueryPerformanceCounter()", "clock()"...
Je ne sais pas comment je vais utiliser et appeler ce code dans mon programme C ?
Merci.
On 10 sep, 21:09, programmation <bouali.a...@gmail.com> wrote:
On 10 sep, 15:52, Christian ASTOR <casto...@club-internet.fr> wrote:
> On 10 sep, 15:03, programmation <bouali.a...@gmail.com> wrote:
> > > Voir la fonction DoBench() avec QueryPerformanceCounter() du vieil
> > > article :http://msdn.microsoft.com/en-us/library/aa260969(VS.60).as px
> > Mais, cette fonction utilise la fonction time() donc pourquoi pas on
> > utilise directement time() ?
> Hein ?!!
> Elle utilise QueryPerformanceCounter() !!!
Bonjour,
Voici le code que je trouve dans ce lien
http://msdn.microsoft.com/en-us/library/aa260969(VS.60).aspx
#include "time.h"
enum { ttuUnknown, ttuHiRes, ttuClock } TimerToUse = ttuUnknown;
LARGE_INTEGER PerfFreq; // ticks per second
int PerfFreqAdjust; // in case Freq is too big
int OverheadTicks; // overhead in calling timer
// Assume the worst
TimerToUse = ttuClock;
if ( QueryPerformanceFrequency(&PerfFreq) )
{
// We can use hires timer, determine overhead
TimerToUse = ttuHiRes;
OverheadTicks = 200;
for ( int i=0; i < 20; i++ )
{
LARGE_INTEGER b,e;
int Ticks;
QueryPerformanceCounter(&b);
(*pFunc)();
QueryPerformanceCounter(&e);
Ticks = e.LowPart - b.LowPart;
if ( Ticks >= 0 && Ticks < OverheadTicks )
OverheadTicks = Ticks;
}
// See if Freq fits in 32 bits; if not lose some precision
PerfFreqAdjust = 0;
int High32 = PerfFreq.HighPart;
while ( High32 )
{
High32 >>= 1;
PerfFreqAdjust++;
}
}
return;
}
double DoBench(void(*funcp)())
{
double time; /* Elapsed time */
// Let any other stuff happen before we start
MSG msg;
PeekMessage(&msg,NULL,NULL,NULL,PM_NOREMOVE);
Sleep(0);
if ( TimerToUse == ttuUnknown )
DetermineTimer();
if ( TimerToUse == ttuHiRes )
{
LARGE_INTEGER tStart, tStop;
LARGE_INTEGER Freq = PerfFreq;
int Oht = OverheadTicks;
int ReduceMag = 0;
SetThreadPriority(GetCurrentThread(),
THREAD_PRIORITY_TIME_CRITICAL);
QueryPerformanceCounter(&tStart);
(*funcp)(); //call the actual function being timed
QueryPerformanceCounter(&tStop);
SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_NORMAL);
// Results are 64 bits but we only do 32
unsigned int High32 = tStop.HighPart - tStart.HighPart;
while ( High32 )
{
High32 >>= 1;
ReduceMag++;
}
if ( PerfFreqAdjust || ReduceMag )
{
if ( PerfFreqAdjust > ReduceMag )
ReduceMag = PerfFreqAdjust;
tStart.QuadPart = Int64ShrlMod32(tStart.QuadPart, ReduceMag);
tStop.QuadPart = Int64ShrlMod32(tStop.QuadPart, ReduceMag);
Freq.QuadPart = Int64ShrlMod32(Freq.QuadPart, ReduceMag);
Oht >>= ReduceMag;
}
// Reduced numbers to 32 bits, now can do the math
if ( Freq.LowPart == 0 )
time = 0.0;
else
time = ((double)(tStop.LowPart - tStart.LowPart
- Oht))/Freq.LowPart;
}
else
{
long stime, etime;
SetThreadPriority(GetCurrentThread(),
THREAD_PRIORITY_TIME_CRITICAL);
stime = clock();
(*funcp)();
etime = clock();
SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_NORMAL);
time = ((double)(etime - stime)) / CLOCKS_PER_SEC;
}
return (time);
}
dans ce code il y a les fonctions comme "QueryPerformanceCounter()",
"clock()"...
Je ne sais pas comment je vais utiliser et appeler ce code dans mon
programme C ?
> > > Voir la fonction DoBench() avec QueryPerformanceCounter() du vieil > > > article :http://msdn.microsoft.com/en-us/library/aa260969(VS.60).as px > > Mais, cette fonction utilise la fonction time() donc pourquoi pas on > > utilise directement time() ?
> Hein ?!! > Elle utilise QueryPerformanceCounter() !!!
Bonjour,
Voici le code que je trouve dans ce lien http://msdn.microsoft.com/en-us/library/aa260969(VS.60).aspx
#include "time.h"
enum { ttuUnknown, ttuHiRes, ttuClock } TimerToUse = ttuUnknown; LARGE_INTEGER PerfFreq; // ticks per second int PerfFreqAdjust; // in case Freq is too big int OverheadTicks; // overhead in calling timer
// Assume the worst TimerToUse = ttuClock; if ( QueryPerformanceFrequency(&PerfFreq) ) { // We can use hires timer, determine overhead TimerToUse = ttuHiRes; OverheadTicks = 200; for ( int i=0; i < 20; i++ ) { LARGE_INTEGER b,e; int Ticks; QueryPerformanceCounter(&b); (*pFunc)(); QueryPerformanceCounter(&e); Ticks = e.LowPart - b.LowPart; if ( Ticks >= 0 && Ticks < OverheadTicks ) OverheadTicks = Ticks; } // See if Freq fits in 32 bits; if not lose some precision PerfFreqAdjust = 0; int High32 = PerfFreq.HighPart; while ( High32 ) { High32 >>= 1; PerfFreqAdjust++; } } return; }
double DoBench(void(*funcp)()) { double time; /* Elapsed time */
// Let any other stuff happen before we start MSG msg; PeekMessage(&msg,NULL,NULL,NULL,PM_NOREMOVE); Sleep(0);
if ( TimerToUse == ttuUnknown ) DetermineTimer();
if ( TimerToUse == ttuHiRes ) { LARGE_INTEGER tStart, tStop; LARGE_INTEGER Freq = PerfFreq; int Oht = OverheadTicks; int ReduceMag = 0; SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_TIME_CRITICAL); QueryPerformanceCounter(&tStart); (*funcp)(); //call the actual function being timed QueryPerformanceCounter(&tStop); SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_NORMAL); // Results are 64 bits but we only do 32 unsigned int High32 = tStop.HighPart - tStart.HighPart; while ( High32 ) { High32 >>= 1; ReduceMag++; } if ( PerfFreqAdjust || ReduceMag ) { if ( PerfFreqAdjust > ReduceMag ) ReduceMag = PerfFreqAdjust; tStart.QuadPart = Int64ShrlMod32(tStart.QuadPart, ReduceMag); tStop.QuadPart = Int64ShrlMod32(tStop.QuadPart, ReduceMag); Freq.QuadPart = Int64ShrlMod32(Freq.QuadPart, ReduceMag); Oht >>= ReduceMag; }
// Reduced numbers to 32 bits, now can do the math if ( Freq.LowPart == 0 ) time = 0.0; else time = ((double)(tStop.LowPart - tStart.LowPart - Oht))/Freq.LowPart; } else { long stime, etime; SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_TIME_CRITICAL); stime = clock(); (*funcp)(); etime = clock(); SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_NORMAL); time = ((double)(etime - stime)) / CLOCKS_PER_SEC; }
return (time); }
dans ce code il y a les fonctions comme "QueryPerformanceCounter()", "clock()"...
Je ne sais pas comment je vais utiliser et appeler ce code dans mon programme C ?
Merci.
Christian ASTOR
On 11 sep, 07:42, programmation wrote:
Je ne sais pas comment je vais utiliser et appeler ce code dans mon programme C ?
En passant une fonction en paramètre de DoBench()... Sinon, en simplifié =>