Changeset 1309
- Timestamp:
- Apr 29, 2012, 10:02:20 PM (11 years ago)
- Location:
- trunk
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/debug/fps.cpp
r866 r1309 64 64 #if 0 65 65 sprintf(buf, "%2.2f fps (%i)", 66 1 e3f / Profiler::GetAvg(Profiler::STAT_TICK_FRAME),66 1.0f / Profiler::GetAvg(Profiler::STAT_TICK_FRAME), 67 67 Ticker::GetFrameNum()); 68 68 data->lines[0]->SetText(buf); 69 69 70 70 sprintf(buf, "Game % 7.2f % 7.2f", 71 Profiler::GetAvg(Profiler::STAT_TICK_GAME),72 Profiler::GetMax(Profiler::STAT_TICK_GAME));71 1e3f * Profiler::GetAvg(Profiler::STAT_TICK_GAME), 72 1e3f * Profiler::GetMax(Profiler::STAT_TICK_GAME)); 73 73 data->lines[1]->SetText(buf); 74 74 75 75 sprintf(buf, "Draw % 7.2f % 7.2f", 76 Profiler::GetAvg(Profiler::STAT_TICK_DRAW),77 Profiler::GetMax(Profiler::STAT_TICK_DRAW));76 1e3f * Profiler::GetAvg(Profiler::STAT_TICK_DRAW), 77 1e3f * Profiler::GetMax(Profiler::STAT_TICK_DRAW)); 78 78 data->lines[2]->SetText(buf); 79 79 80 80 sprintf(buf, "Blit % 7.2f % 7.2f", 81 Profiler::GetAvg(Profiler::STAT_TICK_BLIT),82 Profiler::GetMax(Profiler::STAT_TICK_BLIT));81 1e3f * Profiler::GetAvg(Profiler::STAT_TICK_BLIT), 82 1e3f * Profiler::GetMax(Profiler::STAT_TICK_BLIT)); 83 83 data->lines[3]->SetText(buf); 84 84 85 85 sprintf(buf, "Frame % 7.2f % 7.2f", 86 Profiler::GetAvg(Profiler::STAT_TICK_FRAME),87 Profiler::GetMax(Profiler::STAT_TICK_FRAME));86 1e3f * Profiler::GetAvg(Profiler::STAT_TICK_FRAME), 87 1e3f * Profiler::GetMax(Profiler::STAT_TICK_FRAME)); 88 88 data->lines[4]->SetText(buf); 89 89 #else 90 90 sprintf(buf, "%2.2f/%2.2f/%2.2f/%2.2f %2.2f fps (%i)", 91 Profiler::GetAvg(Profiler::STAT_TICK_GAME),92 Profiler::GetAvg(Profiler::STAT_TICK_DRAW),93 Profiler::GetAvg(Profiler::STAT_TICK_BLIT),94 Profiler::GetAvg(Profiler::STAT_TICK_FRAME),95 1 e3f / Profiler::GetAvg(Profiler::STAT_TICK_FRAME),91 1e3f * Profiler::GetAvg(Profiler::STAT_TICK_GAME), 92 1e3f * Profiler::GetAvg(Profiler::STAT_TICK_DRAW), 93 1e3f * Profiler::GetAvg(Profiler::STAT_TICK_BLIT), 94 1e3f * Profiler::GetAvg(Profiler::STAT_TICK_FRAME), 95 1.0f / Profiler::GetAvg(Profiler::STAT_TICK_FRAME), 96 96 Ticker::GetFrameNum()); 97 97 data->lines[0]->SetText(buf); -
trunk/src/profiler.cpp
r735 r1309 52 52 void Profiler::Start(int id) 53 53 { 54 data[id].timer.Get Ms();54 data[id].timer.Get(); 55 55 } 56 56 57 57 void Profiler::Stop(int id) 58 58 { 59 float deltams = data[id].timer.GetMs();59 float seconds = data[id].timer.Get(); 60 60 61 data[id].history[Ticker::GetFrameNum() % ProfilerData::HISTORY] = deltams;61 data[id].history[Ticker::GetFrameNum() % ProfilerData::HISTORY] = seconds; 62 62 data[id].avg = 0.0f; 63 63 data[id].max = 0.0f; -
trunk/src/ticker.cpp
r1144 r1309 189 189 else 190 190 { 191 data->deltams = data->timer.GetMs();191 data->deltams = 1000.0f * data->timer.Get(); 192 192 data->bias += data->deltams; 193 193 } … … 397 397 framems = data->bias + 200.0f; // Don't go below 5 fps 398 398 if (framems > data->bias) 399 data->timer.Wait Ms(framems - data->bias);399 data->timer.Wait(1e-3f * (framems - data->bias)); 400 400 401 401 /* If recording, do not try to compensate for lag. */ -
trunk/src/timer.cpp
r1173 r1309 63 63 } 64 64 65 float GetOrWait(float deltams, bool update)65 float GetOrWait(float seconds, bool update) 66 66 { 67 float ret,towait;67 float secs_elapsed, secs_towait; 68 68 #if defined __linux__ || defined __native_client__ || defined __APPLE__ 69 69 struct timeval tv; 70 70 gettimeofday(&tv, NULL); 71 ret = 1e-3f * (tv.tv_usec - tv0.tv_usec)72 + 1e3f *(tv.tv_sec - tv0.tv_sec);71 secs_elapsed = 1e-6f * (tv.tv_usec - tv0.tv_usec) 72 + (tv.tv_sec - tv0.tv_sec); 73 73 if (update) 74 74 tv0 = tv; 75 towait = deltams - ret;76 if ( towait > 0.0f)77 usleep((int)( towait * 1e3f));75 secs_towait = seconds - secs_elapsed; 76 if (secs_towait > 0.0f) 77 usleep((int)(secs_towait * 1e6f)); 78 78 #elif defined _WIN32 79 79 LARGE_INTEGER cycles; 80 80 QueryPerformanceCounter(&cycles); 81 static float ms_per_cycle = GetMsPerCycle();82 ret = ms_per_cycle * (cycles.QuadPart - cycles0.QuadPart);81 static float secs_per_cycle = GetSecondsPerCycle(); 82 secs_elapsed = secs_per_cycle * (cycles.QuadPart - cycles0.QuadPart); 83 83 if (update) 84 84 cycles0 = cycles; 85 towait = deltams - ret;86 if ( towait > 5e-4f)87 Sleep((int)( towait+ 0.5f));85 secs_towait = seconds - secs_elapsed; 86 if (secs_towait > 5e-4f) 87 Sleep((int)(secs_towait * 1e3f + 0.5f)); 88 88 #elif defined __CELLOS_LV2__ 89 89 uint64_t cycles; 90 90 SYS_TIMEBASE_GET(cycles); 91 static float ms_per_cycle = GetMsPerCycle();92 ret = ms_per_cycle * (cycles - cycles0);91 static float secs_per_cycle = GetSecondsPerCycle(); 92 secs_elapsed = secs_per_cycle * (cycles - cycles0); 93 93 if (update) 94 94 cycles0 = cycles; 95 towait = deltams - ret;96 if ( towait > 0.0f)97 sys_timer_usleep((int)( towait * 1e3f));95 secs_towait = seconds - secs_elapsed; 96 if (secs_towait > 0.0f) 97 sys_timer_usleep((int)(secs_towait * 1e6f)); 98 98 #else 99 99 /* The crappy SDL fallback */ 100 100 Uint32 ticks = SDL_GetTicks(); 101 ret = ticks - ticks0;101 secs_elapsed = 1e-3f * (ticks - ticks0); 102 102 if (update) 103 103 ticks0 = ticks; 104 towait = deltams - ret;105 if ( towait > 0.5f)106 SDL_Delay((int)( towait+ 0.5f));104 secs_towait = seconds - secs_elapsed; 105 if (secs_towait > 5e-4f) 106 SDL_Delay((int)(secs_towait * 1e3f + 0.5f)); 107 107 #endif 108 return ret;108 return secs_elapsed; 109 109 } 110 110 111 static float Get MsPerCycle()111 static float GetSecondsPerCycle() 112 112 { 113 113 #if defined __linux__ || defined __native_client__ || defined __APPLE__ 114 return 1 .0f;114 return 1e-3f; 115 115 #elif defined _WIN32 116 116 LARGE_INTEGER tmp; 117 117 QueryPerformanceFrequency(&tmp); 118 return 1 e3f / tmp.QuadPart;118 return 1.f / tmp.QuadPart; 119 119 #elif defined __CELLOS_LV2__ 120 return 1 e3f / sys_time_get_timebase_frequency();120 return 1.f / sys_time_get_timebase_frequency(); 121 121 #else 122 return 1 .0f;122 return 1e-3f; 123 123 #endif 124 124 } … … 149 149 } 150 150 151 float Timer::Get Ms()151 float Timer::Get() 152 152 { 153 153 return data->GetOrWait(0.0f, true); 154 154 } 155 155 156 float Timer::Poll Ms()156 float Timer::Poll() 157 157 { 158 158 return data->GetOrWait(0.0f, false); 159 159 } 160 160 161 void Timer::Wait Ms(float deltams)161 void Timer::Wait(float seconds) 162 162 { 163 (void)data->GetOrWait( deltams, false);163 (void)data->GetOrWait(seconds, false); 164 164 } 165 165 -
trunk/src/timer.h
r748 r1309 28 28 ~Timer(); 29 29 30 float Get Ms();31 float Poll Ms();32 void Wait Ms(float deltams);30 float Get(); 31 float Poll(); 32 void Wait(float seconds); 33 33 34 34 private: -
trunk/test/benchmark/half.cpp
r942 r1309 47 47 48 48 /* Copy float */ 49 timer.Get Ms();49 timer.Get(); 50 50 for (size_t i = 0; i < HALF_TABLE_SIZE; i++) 51 51 pf[i] = pf[i + 1]; 52 result[0] += timer.Get Ms();52 result[0] += timer.Get(); 53 53 54 54 /* Convert half to float (array) */ 55 timer.Get Ms();55 timer.Get(); 56 56 half::convert(pf, ph, HALF_TABLE_SIZE); 57 result[1] += timer.Get Ms();57 result[1] += timer.Get(); 58 58 59 59 /* Convert half to float (fast) */ 60 timer.Get Ms();60 timer.Get(); 61 61 for (size_t i = 0; i < HALF_TABLE_SIZE; i++) 62 62 pf[i] = (float)ph[i]; 63 result[2] += timer.Get Ms();63 result[2] += timer.Get(); 64 64 65 65 /* Add a half to every float */ 66 timer.Get Ms();66 timer.Get(); 67 67 for (size_t i = 0; i < HALF_TABLE_SIZE; i++) 68 68 pf[i] += ph[i]; 69 result[3] += timer.Get Ms();69 result[3] += timer.Get(); 70 70 71 71 /* Copy half */ 72 timer.Get Ms();72 timer.Get(); 73 73 for (size_t i = 0; i < HALF_TABLE_SIZE; i++) 74 74 ph[i] = ph[i + 1]; 75 result[4] += timer.Get Ms();75 result[4] += timer.Get(); 76 76 77 77 /* Change sign of every half */ 78 timer.Get Ms();78 timer.Get(); 79 79 for (size_t i = 0; i < HALF_TABLE_SIZE; i++) 80 80 ph[i] = -ph[i]; 81 result[5] += timer.Get Ms();81 result[5] += timer.Get(); 82 82 83 83 /* Convert float to half (array) */ 84 timer.Get Ms();84 timer.Get(); 85 85 half::convert(ph, pf, HALF_TABLE_SIZE); 86 result[6] += timer.Get Ms();86 result[6] += timer.Get(); 87 87 88 88 /* Convert float to half (fast) */ 89 timer.Get Ms();89 timer.Get(); 90 90 for (size_t i = 0; i < HALF_TABLE_SIZE; i++) 91 91 ph[i] = (half)pf[i]; 92 result[7] += timer.Get Ms();92 result[7] += timer.Get(); 93 93 94 94 /* Convert float to half (accurate) */ 95 timer.Get Ms();95 timer.Get(); 96 96 for (size_t i = 0; i < HALF_TABLE_SIZE; i++) 97 97 ph[i] = half::makeaccurate(pf[i]); 98 result[8] += timer.Get Ms();98 result[8] += timer.Get(); 99 99 100 100 /* Add a float to every half */ 101 timer.Get Ms();101 timer.Get(); 102 102 for (size_t i = 0; i < HALF_TABLE_SIZE; i++) 103 103 ph[i] += pf[i]; 104 result[9] += timer.Get Ms();104 result[9] += timer.Get(); 105 105 } 106 106 … … 109 109 110 110 for (size_t i = 0; i < sizeof(result) / sizeof(*result); i++) 111 result[i] *= 1 000000.0f / (HALF_TABLE_SIZE * HALF_RUNS);111 result[i] *= 1e9f / (HALF_TABLE_SIZE * HALF_RUNS); 112 112 113 113 Log::Info(" ns/elem\n"); -
trunk/test/benchmark/real.cpp
r1020 r1309 37 37 38 38 real fib1 = 1.0, fib2 = 1.0; 39 timer.Get Ms();39 timer.Get(); 40 40 for (size_t i = 0; i < REAL_TABLE_SIZE; i++) 41 41 { … … 44 44 fib2 = tmp; 45 45 } 46 result[0] += timer.Get Ms();46 result[0] += timer.Get(); 47 47 48 48 real fact = 1.0; 49 timer.Get Ms();49 timer.Get(); 50 50 for (size_t i = 0; i < REAL_TABLE_SIZE; i++) 51 51 fact = fact * real(1.0 + i); 52 result[1] += timer.Get Ms();52 result[1] += timer.Get(); 53 53 54 54 real invfact = 1.0; 55 timer.Get Ms();55 timer.Get(); 56 56 for (size_t i = 0; i < REAL_TABLE_SIZE; i++) 57 57 invfact = invfact / real(1.0 + i); 58 result[2] += timer.Get Ms();58 result[2] += timer.Get(); 59 59 60 timer.Get Ms();60 timer.Get(); 61 61 for (size_t i = 0; i < REAL_TABLE_SIZE / 128; i++) 62 62 sin(real(0.01 * i)); 63 result[3] += timer.Get Ms() * 128;63 result[3] += timer.Get() * 128; 64 64 65 timer.Get Ms();65 timer.Get(); 66 66 for (size_t i = 0; i < REAL_TABLE_SIZE / 128; i++) 67 67 exp((real)(int)(i - REAL_TABLE_SIZE / 256)); 68 result[4] += timer.Get Ms() * 128;68 result[4] += timer.Get() * 128; 69 69 } 70 70 71 71 for (size_t i = 0; i < sizeof(result) / sizeof(*result); i++) 72 result[i] *= 1 000000.0f / (REAL_TABLE_SIZE * REAL_RUNS);72 result[i] *= 1e9f / (REAL_TABLE_SIZE * REAL_RUNS); 73 73 74 74 Log::Info(" ns/elem\n"); -
trunk/test/benchmark/trig.cpp
r1189 r1309 65 65 66 66 /* Sin */ 67 timer.Get Ms();67 timer.Get(); 68 68 for (size_t i = 0; i < TRIG_TABLE_SIZE; i++) 69 69 #if defined __GNUC__ && !defined __SNC__ … … 72 72 pf2[i] = sinf(pf[i]); 73 73 #endif 74 result[0] += timer.Get Ms();74 result[0] += timer.Get(); 75 75 76 76 /* Fast sin */ 77 timer.Get Ms();77 timer.Get(); 78 78 for (size_t i = 0; i < TRIG_TABLE_SIZE; i++) 79 79 #if defined HAVE_FASTMATH_H && !defined __native_client__ … … 82 82 pf2[i] = sinf(pf[i]); 83 83 #endif 84 result[1] += timer.Get Ms();84 result[1] += timer.Get(); 85 85 86 86 /* Lol sin */ 87 timer.Get Ms();87 timer.Get(); 88 88 for (size_t i = 0; i < TRIG_TABLE_SIZE; i++) 89 89 pf2[i] = lol_sin(pf[i]); 90 result[2] += timer.Get Ms();90 result[2] += timer.Get(); 91 91 92 92 /* Cos */ 93 timer.Get Ms();93 timer.Get(); 94 94 for (size_t i = 0; i < TRIG_TABLE_SIZE; i++) 95 95 #if defined __GNUC__ && !defined __SNC__ … … 98 98 pf2[i] = cosf(pf[i]); 99 99 #endif 100 result[3] += timer.Get Ms();100 result[3] += timer.Get(); 101 101 102 102 /* Fast cos */ 103 timer.Get Ms();103 timer.Get(); 104 104 for (size_t i = 0; i < TRIG_TABLE_SIZE; i++) 105 105 #if defined HAVE_FASTMATH_H && !defined __native_client__ … … 108 108 pf2[i] = cosf(pf[i]); 109 109 #endif 110 result[4] += timer.Get Ms();110 result[4] += timer.Get(); 111 111 112 112 /* Lol cos */ 113 timer.Get Ms();113 timer.Get(); 114 114 for (size_t i = 0; i < TRIG_TABLE_SIZE; i++) 115 115 pf2[i] = lol_cos(pf[i]); 116 result[5] += timer.Get Ms();116 result[5] += timer.Get(); 117 117 118 118 /* Sin & cos */ 119 timer.Get Ms();119 timer.Get(); 120 120 for (size_t i = 0; i < TRIG_TABLE_SIZE; i++) 121 121 { … … 128 128 #endif 129 129 } 130 result[6] += timer.Get Ms();130 result[6] += timer.Get(); 131 131 132 132 /* Fast sin & cos */ 133 timer.Get Ms();133 timer.Get(); 134 134 for (size_t i = 0; i < TRIG_TABLE_SIZE; i++) 135 135 { … … 142 142 #endif 143 143 } 144 result[7] += timer.Get Ms();144 result[7] += timer.Get(); 145 145 146 146 /* Lol sincos */ 147 timer.Get Ms();147 timer.Get(); 148 148 for (size_t i = 0; i < TRIG_TABLE_SIZE; i++) 149 149 lol_sincos(pf[i], &pf2[i], &pf3[i]); 150 result[8] += timer.Get Ms();150 result[8] += timer.Get(); 151 151 152 152 /* Tan */ 153 timer.Get Ms();153 timer.Get(); 154 154 for (size_t i = 0; i < TRIG_TABLE_SIZE; i++) 155 155 #if defined __GNUC__ && !defined __SNC__ … … 158 158 pf2[i] = tanf(pf[i]); 159 159 #endif 160 result[9] += timer.Get Ms();160 result[9] += timer.Get(); 161 161 162 162 /* Fast tan */ 163 timer.Get Ms();163 timer.Get(); 164 164 for (size_t i = 0; i < TRIG_TABLE_SIZE; i++) 165 165 #if defined HAVE_FASTMATH_H && !defined __native_client__ … … 168 168 pf2[i] = tanf(pf[i]); 169 169 #endif 170 result[10] += timer.Get Ms();170 result[10] += timer.Get(); 171 171 172 172 /* Lol tan */ 173 timer.Get Ms();173 timer.Get(); 174 174 for (size_t i = 0; i < TRIG_TABLE_SIZE; i++) 175 175 pf2[i] = lol_tan(pf[i]); 176 result[11] += timer.Get Ms();176 result[11] += timer.Get(); 177 177 } 178 178 … … 182 182 183 183 for (size_t i = 0; i < sizeof(result) / sizeof(*result); i++) 184 result[i] *= 1 000000.0f / (TRIG_TABLE_SIZE * TRIG_RUNS);184 result[i] *= 1e9f / (TRIG_TABLE_SIZE * TRIG_RUNS); 185 185 186 186 Log::Info(" ns/elem\n"); -
trunk/test/benchmark/vector.cpp
r1257 r1309 45 45 46 46 /* Copy matrices */ 47 timer.Get Ms();47 timer.Get(); 48 48 for (size_t i = 0; i < MATRIX_TABLE_SIZE; i++) 49 49 pm[i] = pm[i + 1]; 50 result[0] += timer.Get Ms();50 result[0] += timer.Get(); 51 51 52 52 /* Determinant */ 53 timer.Get Ms();53 timer.Get(); 54 54 for (size_t i = 0; i < MATRIX_TABLE_SIZE; i++) 55 55 pf[i] = determinant(pm[i]); 56 result[1] += timer.Get Ms();56 result[1] += timer.Get(); 57 57 58 58 /* Multiply matrices */ 59 timer.Get Ms();59 timer.Get(); 60 60 for (size_t i = 0; i < MATRIX_TABLE_SIZE; i++) 61 61 pm[i] *= pm[i + 1]; 62 result[2] += timer.Get Ms();62 result[2] += timer.Get(); 63 63 64 64 /* Add matrices */ 65 timer.Get Ms();65 timer.Get(); 66 66 for (size_t i = 0; i < MATRIX_TABLE_SIZE; i++) 67 67 pm[i] += pm[i + 1]; 68 result[3] += timer.Get Ms();68 result[3] += timer.Get(); 69 69 70 70 /* Invert matrix */ 71 timer.Get Ms();71 timer.Get(); 72 72 for (size_t i = 0; i < MATRIX_TABLE_SIZE; i++) 73 73 pm[i] = inverse(pm[i]); 74 result[4] += timer.Get Ms();74 result[4] += timer.Get(); 75 75 } 76 76 … … 79 79 80 80 for (size_t i = 0; i < sizeof(result) / sizeof(*result); i++) 81 result[i] *= 1 000000.0f / (MATRIX_TABLE_SIZE * MATRIX_RUNS);81 result[i] *= 1e9f / (MATRIX_TABLE_SIZE * MATRIX_RUNS); 82 82 83 83 Log::Info(" ns/elem\n");
Note: See TracChangeset
for help on using the changeset viewer.