home *** CD-ROM | disk | FTP | other *** search
/ GameStar 2006 March / Gamestar_82_2006-03_dvd.iso / DVDStar / Editace / quake4_sdkv10.exe / source / idlib / Timer.cpp < prev    next >
C/C++ Source or Header  |  2005-11-14  |  2KB  |  134 lines

  1.  
  2. #include "precompiled.h"
  3. #pragma hdrstop
  4.  
  5. double idTimer::base = -1.0;
  6.  
  7.  
  8. /*
  9. =================
  10. idTimer::InitBaseClockTicks
  11. =================
  12. */
  13. void idTimer::InitBaseClockTicks( void ) const {
  14.     idTimer timer;
  15.     double ct, b;
  16.     int i;
  17.  
  18.     base = 0.0;
  19.     b = -1.0;
  20.     for ( i = 0; i < 1000; i++ ) {
  21.         timer.Clear();
  22.         timer.Start();
  23.         timer.Stop();
  24.         ct = timer.ClockTicks();
  25.         if ( b < 0.0 || ct < b ) {
  26.             b = ct;
  27.         }
  28.     }
  29.     base = b;
  30. }
  31.  
  32.  
  33. /*
  34. =================
  35. idTimerReport::idTimerReport
  36. =================
  37. */
  38. idTimerReport::idTimerReport() {
  39. }
  40.  
  41. /*
  42. =================
  43. idTimerReport::SetReportName
  44. =================
  45. */
  46. void idTimerReport::SetReportName( const char *name ) {
  47.     reportName = ( name ) ? name : "Timer Report";
  48. }
  49.  
  50. /*
  51. =================
  52. idTimerReport::~idTimerReport
  53. =================
  54. */
  55. idTimerReport::~idTimerReport() {
  56.     Clear();
  57. }
  58.  
  59. /*
  60. =================
  61. idTimerReport::AddReport
  62. =================
  63. */
  64. int idTimerReport::AddReport( const char *name ) {
  65.     if ( name && *name ) {
  66.         names.Append( name );
  67.         return timers.Append( new idTimer() );
  68.     }
  69.     return -1;
  70. }
  71.  
  72. /*
  73. =================
  74. idTimerReport::Clear
  75. =================
  76. */
  77. void idTimerReport::Clear() {
  78.     timers.DeleteContents( true );
  79.     names.Clear();
  80.     reportName.Clear();
  81. }
  82.  
  83. /*
  84. =================
  85. idTimerReport::Reset
  86. =================
  87. */
  88. void idTimerReport::Reset() {
  89.     assert ( timers.Num() == names.Num() );
  90.     for ( int i = 0; i < timers.Num(); i++ ) {
  91.         timers[i]->Clear();
  92.     }
  93. }
  94.  
  95. /*
  96. =================
  97. idTimerReport::AddTime
  98. =================
  99. */
  100. void idTimerReport::AddTime( const char *name, idTimer *time ) {
  101.     assert ( timers.Num() == names.Num() );
  102.     int i;
  103.     for ( i = 0; i < names.Num(); i++ ) {
  104.         if ( names[i].Icmp( name ) == 0 ) {
  105.             *timers[i] += *time;
  106.             break;
  107.         }
  108.     }
  109.     if ( i == names.Num() ) {
  110.         int index = AddReport( name );
  111.         if ( index >= 0 ) {
  112.             timers[index]->Clear();
  113.             *timers[index] += *time;
  114.         }
  115.     }
  116. }
  117.  
  118. /*
  119. =================
  120. idTimerReport::PrintReport
  121. =================
  122. */
  123. void idTimerReport::PrintReport() {
  124.     assert( timers.Num() == names.Num() );
  125.     idLib::common->Printf( "Timing Report for %s\n", reportName.c_str() );
  126.     idLib::common->Printf( "-------------------------------\n" );
  127.     float total = 0.0f;
  128.     for ( int i = 0; i < names.Num(); i++ ) {
  129.         idLib::common->Printf( "%s consumed %5.2f seconds\n", names[i].c_str(), timers[i]->Milliseconds() * 0.001f );
  130.         total += timers[i]->Milliseconds();
  131.     }
  132.     idLib::common->Printf( "Total time for report %s was %5.2f\n\n", reportName.c_str(), total * 0.001f );
  133. }
  134.