Browse Source

core: make timers second-based rather than millisecond-based.

legacy
Sam Hocevar sam 13 years ago
parent
commit
fbaf32f1b9
9 changed files with 121 additions and 121 deletions
  1. +14
    -14
      src/debug/fps.cpp
  2. +3
    -3
      src/profiler.cpp
  3. +2
    -2
      src/ticker.cpp
  4. +31
    -31
      src/timer.cpp
  5. +3
    -3
      src/timer.h
  6. +21
    -21
      test/benchmark/half.cpp
  7. +11
    -11
      test/benchmark/real.cpp
  8. +25
    -25
      test/benchmark/trig.cpp
  9. +11
    -11
      test/benchmark/vector.cpp

+ 14
- 14
src/debug/fps.cpp View File

@@ -63,36 +63,36 @@ void DebugFps::TickGame(float deltams)


#if 0 #if 0
sprintf(buf, "%2.2f fps (%i)", sprintf(buf, "%2.2f fps (%i)",
1e3f / Profiler::GetAvg(Profiler::STAT_TICK_FRAME),
1.0f / Profiler::GetAvg(Profiler::STAT_TICK_FRAME),
Ticker::GetFrameNum()); Ticker::GetFrameNum());
data->lines[0]->SetText(buf); data->lines[0]->SetText(buf);


sprintf(buf, "Game % 7.2f % 7.2f", sprintf(buf, "Game % 7.2f % 7.2f",
Profiler::GetAvg(Profiler::STAT_TICK_GAME),
Profiler::GetMax(Profiler::STAT_TICK_GAME));
1e3f * Profiler::GetAvg(Profiler::STAT_TICK_GAME),
1e3f * Profiler::GetMax(Profiler::STAT_TICK_GAME));
data->lines[1]->SetText(buf); data->lines[1]->SetText(buf);


sprintf(buf, "Draw % 7.2f % 7.2f", sprintf(buf, "Draw % 7.2f % 7.2f",
Profiler::GetAvg(Profiler::STAT_TICK_DRAW),
Profiler::GetMax(Profiler::STAT_TICK_DRAW));
1e3f * Profiler::GetAvg(Profiler::STAT_TICK_DRAW),
1e3f * Profiler::GetMax(Profiler::STAT_TICK_DRAW));
data->lines[2]->SetText(buf); data->lines[2]->SetText(buf);


sprintf(buf, "Blit % 7.2f % 7.2f", sprintf(buf, "Blit % 7.2f % 7.2f",
Profiler::GetAvg(Profiler::STAT_TICK_BLIT),
Profiler::GetMax(Profiler::STAT_TICK_BLIT));
1e3f * Profiler::GetAvg(Profiler::STAT_TICK_BLIT),
1e3f * Profiler::GetMax(Profiler::STAT_TICK_BLIT));
data->lines[3]->SetText(buf); data->lines[3]->SetText(buf);


sprintf(buf, "Frame % 7.2f % 7.2f", sprintf(buf, "Frame % 7.2f % 7.2f",
Profiler::GetAvg(Profiler::STAT_TICK_FRAME),
Profiler::GetMax(Profiler::STAT_TICK_FRAME));
1e3f * Profiler::GetAvg(Profiler::STAT_TICK_FRAME),
1e3f * Profiler::GetMax(Profiler::STAT_TICK_FRAME));
data->lines[4]->SetText(buf); data->lines[4]->SetText(buf);
#else #else
sprintf(buf, "%2.2f/%2.2f/%2.2f/%2.2f %2.2f fps (%i)", sprintf(buf, "%2.2f/%2.2f/%2.2f/%2.2f %2.2f fps (%i)",
Profiler::GetAvg(Profiler::STAT_TICK_GAME),
Profiler::GetAvg(Profiler::STAT_TICK_DRAW),
Profiler::GetAvg(Profiler::STAT_TICK_BLIT),
Profiler::GetAvg(Profiler::STAT_TICK_FRAME),
1e3f / Profiler::GetAvg(Profiler::STAT_TICK_FRAME),
1e3f * Profiler::GetAvg(Profiler::STAT_TICK_GAME),
1e3f * Profiler::GetAvg(Profiler::STAT_TICK_DRAW),
1e3f * Profiler::GetAvg(Profiler::STAT_TICK_BLIT),
1e3f * Profiler::GetAvg(Profiler::STAT_TICK_FRAME),
1.0f / Profiler::GetAvg(Profiler::STAT_TICK_FRAME),
Ticker::GetFrameNum()); Ticker::GetFrameNum());
data->lines[0]->SetText(buf); data->lines[0]->SetText(buf);
#endif #endif


+ 3
- 3
src/profiler.cpp View File

@@ -51,14 +51,14 @@ data[Profiler::STAT_COUNT];


void Profiler::Start(int id) void Profiler::Start(int id)
{ {
data[id].timer.GetMs();
data[id].timer.Get();
} }


void Profiler::Stop(int id) void Profiler::Stop(int id)
{ {
float deltams = data[id].timer.GetMs();
float seconds = data[id].timer.Get();


data[id].history[Ticker::GetFrameNum() % ProfilerData::HISTORY] = deltams;
data[id].history[Ticker::GetFrameNum() % ProfilerData::HISTORY] = seconds;
data[id].avg = 0.0f; data[id].avg = 0.0f;
data[id].max = 0.0f; data[id].max = 0.0f;




+ 2
- 2
src/ticker.cpp View File

@@ -188,7 +188,7 @@ void *TickerData::GameThreadMain(void *p)
} }
else else
{ {
data->deltams = data->timer.GetMs();
data->deltams = 1000.0f * data->timer.Get();
data->bias += data->deltams; data->bias += data->deltams;
} }


@@ -396,7 +396,7 @@ void Ticker::TickDraw()
if (framems > data->bias + 200.0f) if (framems > data->bias + 200.0f)
framems = data->bias + 200.0f; // Don't go below 5 fps framems = data->bias + 200.0f; // Don't go below 5 fps
if (framems > data->bias) if (framems > data->bias)
data->timer.WaitMs(framems - data->bias);
data->timer.Wait(1e-3f * (framems - data->bias));


/* If recording, do not try to compensate for lag. */ /* If recording, do not try to compensate for lag. */
if (!data->recording) if (!data->recording)


+ 31
- 31
src/timer.cpp View File

@@ -62,64 +62,64 @@ private:
#endif #endif
} }


float GetOrWait(float deltams, bool update)
float GetOrWait(float seconds, bool update)
{ {
float ret, towait;
float secs_elapsed, secs_towait;
#if defined __linux__ || defined __native_client__ || defined __APPLE__ #if defined __linux__ || defined __native_client__ || defined __APPLE__
struct timeval tv; struct timeval tv;
gettimeofday(&tv, NULL); gettimeofday(&tv, NULL);
ret = 1e-3f * (tv.tv_usec - tv0.tv_usec)
+ 1e3f * (tv.tv_sec - tv0.tv_sec);
secs_elapsed = 1e-6f * (tv.tv_usec - tv0.tv_usec)
+ (tv.tv_sec - tv0.tv_sec);
if (update) if (update)
tv0 = tv; tv0 = tv;
towait = deltams - ret;
if (towait > 0.0f)
usleep((int)(towait * 1e3f));
secs_towait = seconds - secs_elapsed;
if (secs_towait > 0.0f)
usleep((int)(secs_towait * 1e6f));
#elif defined _WIN32 #elif defined _WIN32
LARGE_INTEGER cycles; LARGE_INTEGER cycles;
QueryPerformanceCounter(&cycles); QueryPerformanceCounter(&cycles);
static float ms_per_cycle = GetMsPerCycle();
ret = ms_per_cycle * (cycles.QuadPart - cycles0.QuadPart);
static float secs_per_cycle = GetSecondsPerCycle();
secs_elapsed = secs_per_cycle * (cycles.QuadPart - cycles0.QuadPart);
if (update) if (update)
cycles0 = cycles; cycles0 = cycles;
towait = deltams - ret;
if (towait > 5e-4f)
Sleep((int)(towait + 0.5f));
secs_towait = seconds - secs_elapsed;
if (secs_towait > 5e-4f)
Sleep((int)(secs_towait * 1e3f + 0.5f));
#elif defined __CELLOS_LV2__ #elif defined __CELLOS_LV2__
uint64_t cycles; uint64_t cycles;
SYS_TIMEBASE_GET(cycles); SYS_TIMEBASE_GET(cycles);
static float ms_per_cycle = GetMsPerCycle();
ret = ms_per_cycle * (cycles - cycles0);
static float secs_per_cycle = GetSecondsPerCycle();
secs_elapsed = secs_per_cycle * (cycles - cycles0);
if (update) if (update)
cycles0 = cycles; cycles0 = cycles;
towait = deltams - ret;
if (towait > 0.0f)
sys_timer_usleep((int)(towait * 1e3f));
secs_towait = seconds - secs_elapsed;
if (secs_towait > 0.0f)
sys_timer_usleep((int)(secs_towait * 1e6f));
#else #else
/* The crappy SDL fallback */ /* The crappy SDL fallback */
Uint32 ticks = SDL_GetTicks(); Uint32 ticks = SDL_GetTicks();
ret = ticks - ticks0;
secs_elapsed = 1e-3f * (ticks - ticks0);
if (update) if (update)
ticks0 = ticks; ticks0 = ticks;
towait = deltams - ret;
if (towait > 0.5f)
SDL_Delay((int)(towait + 0.5f));
secs_towait = seconds - secs_elapsed;
if (secs_towait > 5e-4f)
SDL_Delay((int)(secs_towait * 1e3f + 0.5f));
#endif #endif
return ret;
return secs_elapsed;
} }


static float GetMsPerCycle()
static float GetSecondsPerCycle()
{ {
#if defined __linux__ || defined __native_client__ || defined __APPLE__ #if defined __linux__ || defined __native_client__ || defined __APPLE__
return 1.0f;
return 1e-3f;
#elif defined _WIN32 #elif defined _WIN32
LARGE_INTEGER tmp; LARGE_INTEGER tmp;
QueryPerformanceFrequency(&tmp); QueryPerformanceFrequency(&tmp);
return 1e3f / tmp.QuadPart;
return 1.f / tmp.QuadPart;
#elif defined __CELLOS_LV2__ #elif defined __CELLOS_LV2__
return 1e3f / sys_time_get_timebase_frequency();
return 1.f / sys_time_get_timebase_frequency();
#else #else
return 1.0f;
return 1e-3f;
#endif #endif
} }


@@ -148,19 +148,19 @@ Timer::~Timer()
delete data; delete data;
} }


float Timer::GetMs()
float Timer::Get()
{ {
return data->GetOrWait(0.0f, true); return data->GetOrWait(0.0f, true);
} }


float Timer::PollMs()
float Timer::Poll()
{ {
return data->GetOrWait(0.0f, false); return data->GetOrWait(0.0f, false);
} }


void Timer::WaitMs(float deltams)
void Timer::Wait(float seconds)
{ {
(void)data->GetOrWait(deltams, false);
(void)data->GetOrWait(seconds, false);
} }


} /* namespace lol */ } /* namespace lol */


+ 3
- 3
src/timer.h View File

@@ -27,9 +27,9 @@ public:
Timer(); Timer();
~Timer(); ~Timer();


float GetMs();
float PollMs();
void WaitMs(float deltams);
float Get();
float Poll();
void Wait(float seconds);


private: private:
TimerData *data; TimerData *data;


+ 21
- 21
test/benchmark/half.cpp View File

@@ -46,69 +46,69 @@ void bench_half(int mode)
} }


/* Copy float */ /* Copy float */
timer.GetMs();
timer.Get();
for (size_t i = 0; i < HALF_TABLE_SIZE; i++) for (size_t i = 0; i < HALF_TABLE_SIZE; i++)
pf[i] = pf[i + 1]; pf[i] = pf[i + 1];
result[0] += timer.GetMs();
result[0] += timer.Get();


/* Convert half to float (array) */ /* Convert half to float (array) */
timer.GetMs();
timer.Get();
half::convert(pf, ph, HALF_TABLE_SIZE); half::convert(pf, ph, HALF_TABLE_SIZE);
result[1] += timer.GetMs();
result[1] += timer.Get();


/* Convert half to float (fast) */ /* Convert half to float (fast) */
timer.GetMs();
timer.Get();
for (size_t i = 0; i < HALF_TABLE_SIZE; i++) for (size_t i = 0; i < HALF_TABLE_SIZE; i++)
pf[i] = (float)ph[i]; pf[i] = (float)ph[i];
result[2] += timer.GetMs();
result[2] += timer.Get();


/* Add a half to every float */ /* Add a half to every float */
timer.GetMs();
timer.Get();
for (size_t i = 0; i < HALF_TABLE_SIZE; i++) for (size_t i = 0; i < HALF_TABLE_SIZE; i++)
pf[i] += ph[i]; pf[i] += ph[i];
result[3] += timer.GetMs();
result[3] += timer.Get();


/* Copy half */ /* Copy half */
timer.GetMs();
timer.Get();
for (size_t i = 0; i < HALF_TABLE_SIZE; i++) for (size_t i = 0; i < HALF_TABLE_SIZE; i++)
ph[i] = ph[i + 1]; ph[i] = ph[i + 1];
result[4] += timer.GetMs();
result[4] += timer.Get();


/* Change sign of every half */ /* Change sign of every half */
timer.GetMs();
timer.Get();
for (size_t i = 0; i < HALF_TABLE_SIZE; i++) for (size_t i = 0; i < HALF_TABLE_SIZE; i++)
ph[i] = -ph[i]; ph[i] = -ph[i];
result[5] += timer.GetMs();
result[5] += timer.Get();


/* Convert float to half (array) */ /* Convert float to half (array) */
timer.GetMs();
timer.Get();
half::convert(ph, pf, HALF_TABLE_SIZE); half::convert(ph, pf, HALF_TABLE_SIZE);
result[6] += timer.GetMs();
result[6] += timer.Get();


/* Convert float to half (fast) */ /* Convert float to half (fast) */
timer.GetMs();
timer.Get();
for (size_t i = 0; i < HALF_TABLE_SIZE; i++) for (size_t i = 0; i < HALF_TABLE_SIZE; i++)
ph[i] = (half)pf[i]; ph[i] = (half)pf[i];
result[7] += timer.GetMs();
result[7] += timer.Get();


/* Convert float to half (accurate) */ /* Convert float to half (accurate) */
timer.GetMs();
timer.Get();
for (size_t i = 0; i < HALF_TABLE_SIZE; i++) for (size_t i = 0; i < HALF_TABLE_SIZE; i++)
ph[i] = half::makeaccurate(pf[i]); ph[i] = half::makeaccurate(pf[i]);
result[8] += timer.GetMs();
result[8] += timer.Get();


/* Add a float to every half */ /* Add a float to every half */
timer.GetMs();
timer.Get();
for (size_t i = 0; i < HALF_TABLE_SIZE; i++) for (size_t i = 0; i < HALF_TABLE_SIZE; i++)
ph[i] += pf[i]; ph[i] += pf[i];
result[9] += timer.GetMs();
result[9] += timer.Get();
} }


delete[] pf; delete[] pf;
delete[] ph; delete[] ph;


for (size_t i = 0; i < sizeof(result) / sizeof(*result); i++) for (size_t i = 0; i < sizeof(result) / sizeof(*result); i++)
result[i] *= 1000000.0f / (HALF_TABLE_SIZE * HALF_RUNS);
result[i] *= 1e9f / (HALF_TABLE_SIZE * HALF_RUNS);


Log::Info(" ns/elem\n"); Log::Info(" ns/elem\n");
Log::Info("float = float %7.3f\n", result[0]); Log::Info("float = float %7.3f\n", result[0]);


+ 11
- 11
test/benchmark/real.cpp View File

@@ -36,40 +36,40 @@ void bench_real(int mode)
} }


real fib1 = 1.0, fib2 = 1.0; real fib1 = 1.0, fib2 = 1.0;
timer.GetMs();
timer.Get();
for (size_t i = 0; i < REAL_TABLE_SIZE; i++) for (size_t i = 0; i < REAL_TABLE_SIZE; i++)
{ {
real tmp = fib1 + fib2; real tmp = fib1 + fib2;
fib1 = fib2; fib1 = fib2;
fib2 = tmp; fib2 = tmp;
} }
result[0] += timer.GetMs();
result[0] += timer.Get();


real fact = 1.0; real fact = 1.0;
timer.GetMs();
timer.Get();
for (size_t i = 0; i < REAL_TABLE_SIZE; i++) for (size_t i = 0; i < REAL_TABLE_SIZE; i++)
fact = fact * real(1.0 + i); fact = fact * real(1.0 + i);
result[1] += timer.GetMs();
result[1] += timer.Get();


real invfact = 1.0; real invfact = 1.0;
timer.GetMs();
timer.Get();
for (size_t i = 0; i < REAL_TABLE_SIZE; i++) for (size_t i = 0; i < REAL_TABLE_SIZE; i++)
invfact = invfact / real(1.0 + i); invfact = invfact / real(1.0 + i);
result[2] += timer.GetMs();
result[2] += timer.Get();


timer.GetMs();
timer.Get();
for (size_t i = 0; i < REAL_TABLE_SIZE / 128; i++) for (size_t i = 0; i < REAL_TABLE_SIZE / 128; i++)
sin(real(0.01 * i)); sin(real(0.01 * i));
result[3] += timer.GetMs() * 128;
result[3] += timer.Get() * 128;


timer.GetMs();
timer.Get();
for (size_t i = 0; i < REAL_TABLE_SIZE / 128; i++) for (size_t i = 0; i < REAL_TABLE_SIZE / 128; i++)
exp((real)(int)(i - REAL_TABLE_SIZE / 256)); exp((real)(int)(i - REAL_TABLE_SIZE / 256));
result[4] += timer.GetMs() * 128;
result[4] += timer.Get() * 128;
} }


for (size_t i = 0; i < sizeof(result) / sizeof(*result); i++) for (size_t i = 0; i < sizeof(result) / sizeof(*result); i++)
result[i] *= 1000000.0f / (REAL_TABLE_SIZE * REAL_RUNS);
result[i] *= 1e9f / (REAL_TABLE_SIZE * REAL_RUNS);


Log::Info(" ns/elem\n"); Log::Info(" ns/elem\n");
Log::Info("real = real + real %7.3f\n", result[0]); Log::Info("real = real + real %7.3f\n", result[0]);


+ 25
- 25
test/benchmark/trig.cpp View File

@@ -64,59 +64,59 @@ void bench_trig(int mode)
} }


/* Sin */ /* Sin */
timer.GetMs();
timer.Get();
for (size_t i = 0; i < TRIG_TABLE_SIZE; i++) for (size_t i = 0; i < TRIG_TABLE_SIZE; i++)
#if defined __GNUC__ && !defined __SNC__ #if defined __GNUC__ && !defined __SNC__
pf2[i] = __builtin_sinf(pf[i]); pf2[i] = __builtin_sinf(pf[i]);
#else #else
pf2[i] = sinf(pf[i]); pf2[i] = sinf(pf[i]);
#endif #endif
result[0] += timer.GetMs();
result[0] += timer.Get();


/* Fast sin */ /* Fast sin */
timer.GetMs();
timer.Get();
for (size_t i = 0; i < TRIG_TABLE_SIZE; i++) for (size_t i = 0; i < TRIG_TABLE_SIZE; i++)
#if defined HAVE_FASTMATH_H && !defined __native_client__ #if defined HAVE_FASTMATH_H && !defined __native_client__
pf2[i] = f_sinf(pf[i]); pf2[i] = f_sinf(pf[i]);
#else #else
pf2[i] = sinf(pf[i]); pf2[i] = sinf(pf[i]);
#endif #endif
result[1] += timer.GetMs();
result[1] += timer.Get();


/* Lol sin */ /* Lol sin */
timer.GetMs();
timer.Get();
for (size_t i = 0; i < TRIG_TABLE_SIZE; i++) for (size_t i = 0; i < TRIG_TABLE_SIZE; i++)
pf2[i] = lol_sin(pf[i]); pf2[i] = lol_sin(pf[i]);
result[2] += timer.GetMs();
result[2] += timer.Get();


/* Cos */ /* Cos */
timer.GetMs();
timer.Get();
for (size_t i = 0; i < TRIG_TABLE_SIZE; i++) for (size_t i = 0; i < TRIG_TABLE_SIZE; i++)
#if defined __GNUC__ && !defined __SNC__ #if defined __GNUC__ && !defined __SNC__
pf2[i] = __builtin_cosf(pf[i]); pf2[i] = __builtin_cosf(pf[i]);
#else #else
pf2[i] = cosf(pf[i]); pf2[i] = cosf(pf[i]);
#endif #endif
result[3] += timer.GetMs();
result[3] += timer.Get();


/* Fast cos */ /* Fast cos */
timer.GetMs();
timer.Get();
for (size_t i = 0; i < TRIG_TABLE_SIZE; i++) for (size_t i = 0; i < TRIG_TABLE_SIZE; i++)
#if defined HAVE_FASTMATH_H && !defined __native_client__ #if defined HAVE_FASTMATH_H && !defined __native_client__
pf2[i] = f_cosf(pf[i]); pf2[i] = f_cosf(pf[i]);
#else #else
pf2[i] = cosf(pf[i]); pf2[i] = cosf(pf[i]);
#endif #endif
result[4] += timer.GetMs();
result[4] += timer.Get();


/* Lol cos */ /* Lol cos */
timer.GetMs();
timer.Get();
for (size_t i = 0; i < TRIG_TABLE_SIZE; i++) for (size_t i = 0; i < TRIG_TABLE_SIZE; i++)
pf2[i] = lol_cos(pf[i]); pf2[i] = lol_cos(pf[i]);
result[5] += timer.GetMs();
result[5] += timer.Get();


/* Sin & cos */ /* Sin & cos */
timer.GetMs();
timer.Get();
for (size_t i = 0; i < TRIG_TABLE_SIZE; i++) for (size_t i = 0; i < TRIG_TABLE_SIZE; i++)
{ {
#if defined __GNUC__ && !defined __SNC__ #if defined __GNUC__ && !defined __SNC__
@@ -127,10 +127,10 @@ void bench_trig(int mode)
pf3[i] = cosf(pf[i]); pf3[i] = cosf(pf[i]);
#endif #endif
} }
result[6] += timer.GetMs();
result[6] += timer.Get();


/* Fast sin & cos */ /* Fast sin & cos */
timer.GetMs();
timer.Get();
for (size_t i = 0; i < TRIG_TABLE_SIZE; i++) for (size_t i = 0; i < TRIG_TABLE_SIZE; i++)
{ {
#if defined HAVE_FASTMATH_H && !defined __native_client__ #if defined HAVE_FASTMATH_H && !defined __native_client__
@@ -141,39 +141,39 @@ void bench_trig(int mode)
pf3[i] = cosf(pf[i]); pf3[i] = cosf(pf[i]);
#endif #endif
} }
result[7] += timer.GetMs();
result[7] += timer.Get();


/* Lol sincos */ /* Lol sincos */
timer.GetMs();
timer.Get();
for (size_t i = 0; i < TRIG_TABLE_SIZE; i++) for (size_t i = 0; i < TRIG_TABLE_SIZE; i++)
lol_sincos(pf[i], &pf2[i], &pf3[i]); lol_sincos(pf[i], &pf2[i], &pf3[i]);
result[8] += timer.GetMs();
result[8] += timer.Get();


/* Tan */ /* Tan */
timer.GetMs();
timer.Get();
for (size_t i = 0; i < TRIG_TABLE_SIZE; i++) for (size_t i = 0; i < TRIG_TABLE_SIZE; i++)
#if defined __GNUC__ && !defined __SNC__ #if defined __GNUC__ && !defined __SNC__
pf2[i] = __builtin_tanf(pf[i]); pf2[i] = __builtin_tanf(pf[i]);
#else #else
pf2[i] = tanf(pf[i]); pf2[i] = tanf(pf[i]);
#endif #endif
result[9] += timer.GetMs();
result[9] += timer.Get();


/* Fast tan */ /* Fast tan */
timer.GetMs();
timer.Get();
for (size_t i = 0; i < TRIG_TABLE_SIZE; i++) for (size_t i = 0; i < TRIG_TABLE_SIZE; i++)
#if defined HAVE_FASTMATH_H && !defined __native_client__ #if defined HAVE_FASTMATH_H && !defined __native_client__
pf2[i] = f_tanf(pf[i]); pf2[i] = f_tanf(pf[i]);
#else #else
pf2[i] = tanf(pf[i]); pf2[i] = tanf(pf[i]);
#endif #endif
result[10] += timer.GetMs();
result[10] += timer.Get();


/* Lol tan */ /* Lol tan */
timer.GetMs();
timer.Get();
for (size_t i = 0; i < TRIG_TABLE_SIZE; i++) for (size_t i = 0; i < TRIG_TABLE_SIZE; i++)
pf2[i] = lol_tan(pf[i]); pf2[i] = lol_tan(pf[i]);
result[11] += timer.GetMs();
result[11] += timer.Get();
} }


delete[] pf; delete[] pf;
@@ -181,7 +181,7 @@ void bench_trig(int mode)
delete[] pf3; delete[] pf3;


for (size_t i = 0; i < sizeof(result) / sizeof(*result); i++) for (size_t i = 0; i < sizeof(result) / sizeof(*result); i++)
result[i] *= 1000000.0f / (TRIG_TABLE_SIZE * TRIG_RUNS);
result[i] *= 1e9f / (TRIG_TABLE_SIZE * TRIG_RUNS);


Log::Info(" ns/elem\n"); Log::Info(" ns/elem\n");
Log::Info("float = sinf(float) %7.3f\n", result[0]); Log::Info("float = sinf(float) %7.3f\n", result[0]);


+ 11
- 11
test/benchmark/vector.cpp View File

@@ -44,41 +44,41 @@ void bench_matrix(int mode)
} }


/* Copy matrices */ /* Copy matrices */
timer.GetMs();
timer.Get();
for (size_t i = 0; i < MATRIX_TABLE_SIZE; i++) for (size_t i = 0; i < MATRIX_TABLE_SIZE; i++)
pm[i] = pm[i + 1]; pm[i] = pm[i + 1];
result[0] += timer.GetMs();
result[0] += timer.Get();


/* Determinant */ /* Determinant */
timer.GetMs();
timer.Get();
for (size_t i = 0; i < MATRIX_TABLE_SIZE; i++) for (size_t i = 0; i < MATRIX_TABLE_SIZE; i++)
pf[i] = determinant(pm[i]); pf[i] = determinant(pm[i]);
result[1] += timer.GetMs();
result[1] += timer.Get();


/* Multiply matrices */ /* Multiply matrices */
timer.GetMs();
timer.Get();
for (size_t i = 0; i < MATRIX_TABLE_SIZE; i++) for (size_t i = 0; i < MATRIX_TABLE_SIZE; i++)
pm[i] *= pm[i + 1]; pm[i] *= pm[i + 1];
result[2] += timer.GetMs();
result[2] += timer.Get();


/* Add matrices */ /* Add matrices */
timer.GetMs();
timer.Get();
for (size_t i = 0; i < MATRIX_TABLE_SIZE; i++) for (size_t i = 0; i < MATRIX_TABLE_SIZE; i++)
pm[i] += pm[i + 1]; pm[i] += pm[i + 1];
result[3] += timer.GetMs();
result[3] += timer.Get();


/* Invert matrix */ /* Invert matrix */
timer.GetMs();
timer.Get();
for (size_t i = 0; i < MATRIX_TABLE_SIZE; i++) for (size_t i = 0; i < MATRIX_TABLE_SIZE; i++)
pm[i] = inverse(pm[i]); pm[i] = inverse(pm[i]);
result[4] += timer.GetMs();
result[4] += timer.Get();
} }


delete[] pm; delete[] pm;
delete[] pf; delete[] pf;


for (size_t i = 0; i < sizeof(result) / sizeof(*result); i++) for (size_t i = 0; i < sizeof(result) / sizeof(*result); i++)
result[i] *= 1000000.0f / (MATRIX_TABLE_SIZE * MATRIX_RUNS);
result[i] *= 1e9f / (MATRIX_TABLE_SIZE * MATRIX_RUNS);


Log::Info(" ns/elem\n"); Log::Info(" ns/elem\n");
Log::Info("mat4 = mat4 %7.3f\n", result[0]); Log::Info("mat4 = mat4 %7.3f\n", result[0]);


Loading…
Cancel
Save