void Delay_us(int us) { TimeDifferenceStrcut time = {0,0,0}; bool finish = false; time.Past = GetCPUTime(); while(!finish) { time.Now = GetCPUTime(); CalculateTimeDifference_us(&time); if(time.dT > us) { finish = true; } } }
int main(int argc, char* argv[]) { int i; float ft0; long tnow; struct timeval tval; char tstr[64]; // initialize random ft0 = GetCPUTime(); printf(" %7.3fs start\n", ft0); // hiepnh commented // gettimeofday(&tval, 0); // GetTimeStr(&tval, tstr); // tnow = (long) tval.tv_sec*1000 + (long) tval.tv_usec/1000; // srand48(tnow); srand(time(0)); for (i = 1000000; i <= 100000000; i *= 10) { RandBench(i); HashBench(i); FixedVecBench(i); VecBench(i); //SortedVecBench(n); } }
NS_IMETHODIMP nsStopwatch::Resume() { if (!fRunning) { fStartRealTimeSecs = GetRealTime(); fStartCpuTimeSecs = GetCPUTime(); } fRunning = true; return NS_OK; }
// random generation benchmark void RandBench(const int& n) { float ft0, ft1; long Sum; int x; int i; // generate random numbers ft0 = GetCPUTime(); Sum = 0; for (i = 0; i < n; i++) { x = (int) (drand48() * 100000000); Sum += x; } printf("rand: sum %ld\n", Sum); ft1 = GetCPUTime(); printf("rand: %7.3fs generating %d numbers\n",ft1-ft0,i); }
NS_IMETHODIMP nsStopwatch::Stop() { fStopRealTimeSecs = GetRealTime(); fStopCpuTimeSecs = GetCPUTime(); if (fRunning) { fTotalCpuTimeSecs += fStopCpuTimeSecs - fStartCpuTimeSecs; fTotalRealTimeSecs += fStopRealTimeSecs - fStartRealTimeSecs; } fRunning = false; return NS_OK; }
// sorted vector benchmark with integer values void SortedVecBench(const int& n) { TIntV Vec; float ft0, ft1; int x; int i; int Found; int NotFound; int Id; // build the vector ft0 = GetCPUTime(); for (i = 0; i < n; i++) { x = (int) (drand48() * 100000000); //Vec.AddSorted(x); Vec.AddMerged(x); } printf("svec: size %d\n", Vec.Len()); ft1 = GetCPUTime(); printf("svec: %7.3fs inserting %d numbers\n",ft1-ft0,i); // search the vector ft0 = GetCPUTime(); Found = 0; NotFound = 0; for (i = 0; i < n; i++) { x = (int) (drand48() * 100000000); Id = Vec.IsInBin(x); if (Id == 0) { NotFound++; } else { Found++; } } printf("svec: found %d, notfound %d\n", Found, NotFound); ft1 = GetCPUTime(); printf("svec: %7.3fs searching %d numbers\n",ft1-ft0,i); }
// hash table benchmark with integer keys void HashBench(const int& n) { TIntIntH TableInt; float ft0, ft1; int x; int i; int Found; int NotFound; int Id; // build the hash table ft0 = GetCPUTime(); for (i = 0; i < n; i++) { x = (int) (drand48() * 100000000); TableInt.AddDat(x,0); } printf("hash: size %d\n", TableInt.Len()); ft1 = GetCPUTime(); printf("hash: %7.3fs inserting %d numbers\n",ft1-ft0,i); // search the hash table ft0 = GetCPUTime(); Found = 0; NotFound = 0; for (i = 0; i < n; i++) { x = (int) (drand48() * 100000000); Id = TableInt.GetKeyId(x); if (Id < 0) { NotFound++; } else { Found++; } } printf("hash: found %d, notfound %d\n", Found, NotFound); ft1 = GetCPUTime(); printf("hash: %7.3fs searching %d numbers\n",ft1-ft0,i); }
/*----------------------------------------------------------------------------- -----------------------------------------------------------------------------*/ std::string PowerStats::Measure() { std::string response("{"); response += "\"elapsed_time\":" + GetElapsedTime(); // CPU busy time (seconds) response += ",\"cpu_time\":" + GetCPUTime(); // Power Data (including elapsed time) response += GetPowerData(); response += "}"; return response; }
void Stopwatch::Stop() { #ifndef R__UNIX fStopRealTime = GetRealTime(); fStopCpuTime = GetCPUTime(); #else struct tms cpt; fStopRealTime = (double)times(&cpt) / gTicks; fStopCpuTime = (double)(cpt.tms_utime+cpt.tms_stime) / gTicks; #endif if (fState == kRunning) { fTotalCpuTime += fStopCpuTime - fStartCpuTime; fTotalRealTime += fStopRealTime - fStartRealTime; } fState = kStopped; }
void Stopwatch::Start(PRBool reset) { if (reset) { fTotalCpuTime = 0; fTotalRealTime = 0; } if (fState != kRunning) { #ifndef R__UNIX fStartRealTime = GetRealTime(); fStartCpuTime = GetCPUTime(); #else struct tms cpt; fStartRealTime = (double)times(&cpt) / gTicks; fStartCpuTime = (double)(cpt.tms_utime+cpt.tms_stime) / gTicks; #endif } fState = kRunning; }
// fixed vector benchmark with integer values void FixedVecBench(const int& n) { TIntV Vec(100000000); float ft0, ft1; int x; int i; int Found; int NotFound; // set the elements to 0 ft0 = GetCPUTime(); Vec.PutAll(0); printf("fvec: size %d\n", Vec.Len()); ft1 = GetCPUTime(); printf("fvec: %7.3fs zeroing %d numbers\n",ft1-ft0,n); // build the vector ft0 = GetCPUTime(); for (i = 0; i < n; i++) { x = (int) (drand48() * 100000000); Vec[x] = 1; } ft1 = GetCPUTime(); printf("fvec: %7.3fs inserting %d numbers\n",ft1-ft0,i); // search the vector ft0 = GetCPUTime(); Found = 0; NotFound = 0; for (i = 0; i < n; i++) { x = (int) (drand48() * 100000000); if (Vec[x] <= 0) { NotFound++; } else { Found++; } } printf("fvec: found %d, notfound %d\n", Found, NotFound); ft1 = GetCPUTime(); printf("fvec: %7.3fs searching %d numbers\n",ft1-ft0,i); }
/*----------------------------------------------------------------------------- -----------------------------------------------------------------------------*/ void CBrowserEvents::DocumentComplete(CString & szUrl, DWORD code) { CheckReadyState(); // make sure we are actually measuring something if( active ) { CheckStuff(); EnterCriticalSection(&cs); // if we got an error code, use it if( code ) errorCode = code; // update the end time QueryPerfCounter(lastActivity); end = lastActivity; endDoc = end; lastDoc = lastActivity; GetCPUTime(docCPU, docCPUtotal); // throw away any objects that happen outside of a document load currentDoc = 0; LeaveCriticalSection(&cs); // grab a screen shot of the document complete event if( saveEverything ) { FindBrowserWindow(); screenCapture.Capture(hBrowserWnd, CapturedImage::DOCUMENT_COMPLETE); } // update the waterfall RepaintWaterfall(); } else if(szUrl == _T("about:blank")) { FindBrowserWindow(); ResizeWindow(); // reset the UI on an about:blank navigation if( interactive && !available ) { Reset(); available = true; } // see if we have an url to test testUrl.Empty(); testOptions.Empty(); HKEY hKey; if( RegOpenKeyEx(HKEY_CURRENT_USER, _T("SOFTWARE\\AOL\\ieWatch"), 0, KEY_READ | KEY_WRITE, &hKey) == ERROR_SUCCESS ) { // get the url value out TCHAR buff[4096]; DWORD buffLen = sizeof(buff); if( RegQueryValueEx(hKey, _T("url"), 0, 0, (LPBYTE)buff, &buffLen) == ERROR_SUCCESS ) { // delete the value since we already got it and we get a new value there for every run RegDeleteValue(hKey, _T("url")); // split off any options that were embedded in the url CString tmp = buff; int index = tmp.Find(_T("??pt")); if( index >= 0 ) { testUrl = tmp.Left(index); testOptions = tmp.Mid(index + 2); } else testUrl = buff; // if we have an url to test, launch it if( testUrl.GetLength() ) { if( !testUrl.Left(9).CompareNoCase(_T("script://")) ) { CString script = testUrl.Right(testUrl.GetLength() - 9); LoadScript(script); } StartTimer(2, 100); } } RegCloseKey(hKey); } } else { CString buff; buff.Format(_T("[Pagetest] * Document Complete (not active) - %s\n"), (LPCTSTR)szUrl); OutputDebugString(buff); } }
/* ** NAME ** CalculateBasePerfStats ** ** DESCRIPTION ** This is the main function that calculates the stats. Stats ** that we caculate are: ** *uSecs per Packet ** *Packets per Second ** *Mbits per Second ** *Average bytes per Packet ** *CPU Time ** *Dropped Packets ** These statistics are processed and then stored in the ** SFBASE_STATS structure. This allows output functions to ** be easily formed and inserted. ** NOTE: We can break up these statistics into functions for easier ** reading. ** ** FORMAL INPUTS ** SFBASE * - ptr to performance struct ** SFBASE_STATS * - ptr to struct to fill in performance stats ** ** FORMAL OUTPUTS ** int - 0 is successful */ int CalculateBasePerfStats(SFBASE *sfBase, SFBASE_STATS *sfBaseStats) { SYSTIMES Systimes; time_t clock; #ifdef LINUX_SMP /* ** We also give sfBaseStats access to the CPU usage ** contained in sfProcPidStats. This way we don't need ** to complicate sfBaseStats further. */ sfBaseStats->sfProcPidStats = &(sfBase->sfProcPidStats); #endif if(GetProcessingTime(&Systimes, sfBase)) return -1; sfBaseStats->total_blocked_packets = sfBase->total_blocked_packets; /* ** Avg. bytes per Packet */ if (sfBase->total_packets > 0) sfBaseStats->avg_bytes_per_packet = (int)((double)(sfBase->total_bytes) / (double)(sfBase->total_packets)); else sfBaseStats->avg_bytes_per_packet = 0; if (sfBase->total_wire_packets > 0) sfBaseStats->avg_bytes_per_wire_packet = (int)((double)(sfBase->total_wire_bytes) / (double)(sfBase->total_wire_packets)); else sfBaseStats->avg_bytes_per_wire_packet = 0; if (sfBase->total_ipfragmented_packets > 0) sfBaseStats->avg_bytes_per_ipfrag_packet = (int)((double)(sfBase->total_ipfragmented_bytes) / (double)(sfBase->total_ipfragmented_packets)); else sfBaseStats->avg_bytes_per_ipfrag_packet = 0; if (sfBase->total_ipreassembled_packets > 0) sfBaseStats->avg_bytes_per_ipreass_packet = (int)((double)(sfBase->total_ipreassembled_bytes) / (double)(sfBase->total_ipreassembled_packets)); else sfBaseStats->avg_bytes_per_ipreass_packet = 0; if (sfBase->total_rebuilt_packets > 0) sfBaseStats->avg_bytes_per_rebuilt_packet = (int)((double)(sfBase->total_rebuilt_bytes) / (double)(sfBase->total_rebuilt_packets)); else sfBaseStats->avg_bytes_per_rebuilt_packet = 0; /* ** CPU time */ GetCPUTime(sfBase, sfBaseStats, &Systimes); /* ** Get Dropped Packets */ GetPktDropStats(sfBase, sfBaseStats); /* ** Total packets */ sfBaseStats->total_packets = sfBase->total_wire_packets; /* * Pattern Matching Performance in Real and User time */ sfBaseStats->patmatch_percent = 100.0 * mpseGetPatByteCount() / sfBase->total_wire_bytes; mpseResetByteCount(); if(sfBase->iFlags & MAX_PERF_STATS) { /* ** uSeconds per Packet ** user, system, total time */ GetuSecondsPerPacket(sfBase, sfBaseStats, &Systimes); } /* ** Mbits per sec ** user, system, total time */ GetMbitsPerSecond(sfBase, sfBaseStats, &Systimes); /* ** EventsPerSecond ** We get the information from the global variable ** PacketCount. */ GetEventsPerSecond(sfBase, sfBaseStats, &Systimes); /* ** Packets per seconds ** user, system, total time */ GetPacketsPerSecond(sfBase, sfBaseStats, &Systimes); /* ** Set the date string for print out */ time(&clock); sfBaseStats->time = clock; return 0; }
void timestatus ( const int samp_rate, const int frameNum, const int totalframes, const int framesize ) { static timestatus_t real_time; static timestatus_t proc_time; int percent; static int init = 0; /* What happens here? A work around instead of a bug fix ??? */ double tmx,delta; if ( frameNum == 0 ) { real_time.last_time = GetRealTime (); proc_time.last_time = GetCPUTime (); real_time.elapsed_time = 0; proc_time.elapsed_time = 0; } /* we need rollover protection for GetCPUTime, and maybe GetRealTime(): */ tmx=GetRealTime(); delta=tmx-real_time.last_time; if (delta<0) delta=0; /* ignore, clock has rolled over */ real_time.elapsed_time += delta; real_time.last_time = tmx; tmx=GetCPUTime(); delta=tmx-proc_time.last_time; if (delta<0) delta=0; /* ignore, clock has rolled over */ proc_time.elapsed_time += delta; proc_time.last_time = tmx; if ( frameNum == 0 && init == 0 ) { fprintf ( stderr, "\r" " Frame | CPU time/estim | REAL time/estim | play/CPU | ETA \n" " 0/ ( 0%%)| 0:00/ : | 0:00/ : | " SPEED_CHAR "| : \r" /* , Console_IO.str_clreoln, Console_IO.str_clreoln */ ); init = 1; return; } /* reset init counter for next time we are called with frameNum==0 */ if (frameNum > 0) init = 0; ts_calc_times ( &real_time, samp_rate, frameNum, totalframes, framesize ); ts_calc_times ( &proc_time, samp_rate, frameNum, totalframes, framesize ); if ( frameNum < totalframes ) { percent = (int) (100. * frameNum / totalframes + 0.5 ); } else { percent = 100; } fprintf ( stderr, "\r%6i/%-6i", frameNum, totalframes ); fprintf ( stderr, percent < 100 ? " (%2d%%)|" : "(%3.3d%%)|", percent ); ts_time_decompose ( (unsigned long)proc_time.elapsed_time , '/' ); ts_time_decompose ( (unsigned long)proc_time.estimated_time, '|' ); ts_time_decompose ( (unsigned long)real_time.elapsed_time , '/' ); ts_time_decompose ( (unsigned long)real_time.estimated_time, '|' ); fprintf ( stderr, proc_time.speed_index <= 1. ? "%9.4f" SPEED_CHAR "|" : "%#9.5g" SPEED_CHAR "|", SPEED_MULT * proc_time.speed_index ); ts_time_decompose ( (unsigned long)(real_time.estimated_time - real_time.elapsed_time), ' ' ); fflush ( stderr ); }
void vfeTimer::Reset (void) { m_WallTimeStart = GetWallTime(); m_CPUTimeStart = GetCPUTime(); }
POV_LONG vfeTimer::ElapsedCPUTime (void) const { return GetCPUTime() - m_CPUTimeStart; }
static void timestatus(const lame_global_flags * const gfp) { timestatus_t* real_time = &global_encoder_progress.real_time; timestatus_t* proc_time = &global_encoder_progress.proc_time; int percent; double tmx, delta; int samp_rate = lame_get_out_samplerate(gfp) , frameNum = lame_get_frameNum(gfp) , totalframes = lame_get_totalframes(gfp) , framesize = lame_get_framesize(gfp) ; if (totalframes < frameNum) { totalframes = frameNum; } if (global_encoder_progress.time_status_init == 0) { real_time->last_time = GetRealTime(); proc_time->last_time = GetCPUTime(); real_time->elapsed_time = 0; proc_time->elapsed_time = 0; } /* we need rollover protection for GetCPUTime, and maybe GetRealTime(): */ tmx = GetRealTime(); delta = tmx - real_time->last_time; if (delta < 0) delta = 0; /* ignore, clock has rolled over */ real_time->elapsed_time += delta; real_time->last_time = tmx; tmx = GetCPUTime(); delta = tmx - proc_time->last_time; if (delta < 0) delta = 0; /* ignore, clock has rolled over */ proc_time->elapsed_time += delta; proc_time->last_time = tmx; if (global_encoder_progress.time_status_init == 0) { console_printf("\r" " Frame | CPU time/estim | REAL time/estim | play/CPU | ETA \n" " 0/ ( 0%%)| 0:00/ : | 0:00/ : | " SPEED_CHAR "| : \r" /* , Console_IO.str_clreoln, Console_IO.str_clreoln */ ); global_encoder_progress.time_status_init = 1; return; } ts_calc_times(real_time, samp_rate, frameNum, totalframes, framesize); ts_calc_times(proc_time, samp_rate, frameNum, totalframes, framesize); if (frameNum < totalframes) { percent = (int) (100. * frameNum / totalframes + 0.5); } else { percent = 100; } console_printf("\r%6i/%-6i", frameNum, totalframes); console_printf(percent < 100 ? " (%2d%%)|" : "(%3.3d%%)|", percent); ts_time_decompose(proc_time->elapsed_time, '/'); ts_time_decompose(proc_time->estimated_time, '|'); ts_time_decompose(real_time->elapsed_time, '/'); ts_time_decompose(real_time->estimated_time, '|'); console_printf(proc_time->speed_index <= 1. ? "%9.4f" SPEED_CHAR "|" : "%#9.5g" SPEED_CHAR "|", SPEED_MULT * proc_time->speed_index); ts_time_decompose((real_time->estimated_time - real_time->elapsed_time), ' '); }