Changeset 1309


Ignore:
Timestamp:
Apr 29, 2012, 10:02:20 PM (11 years ago)
Author:
sam
Message:

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

Location:
trunk
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/debug/fps.cpp

    r866 r1309  
    6464#if 0
    6565    sprintf(buf, "%2.2f fps (%i)",
    66             1e3f / Profiler::GetAvg(Profiler::STAT_TICK_FRAME),
     66            1.0f / Profiler::GetAvg(Profiler::STAT_TICK_FRAME),
    6767            Ticker::GetFrameNum());
    6868    data->lines[0]->SetText(buf);
    6969
    7070    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));
    7373    data->lines[1]->SetText(buf);
    7474
    7575    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));
    7878    data->lines[2]->SetText(buf);
    7979
    8080    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));
    8383    data->lines[3]->SetText(buf);
    8484
    8585    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));
    8888    data->lines[4]->SetText(buf);
    8989#else
    9090    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             1e3f / 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),
    9696            Ticker::GetFrameNum());
    9797    data->lines[0]->SetText(buf);
  • trunk/src/profiler.cpp

    r735 r1309  
    5252void Profiler::Start(int id)
    5353{
    54     data[id].timer.GetMs();
     54    data[id].timer.Get();
    5555}
    5656
    5757void Profiler::Stop(int id)
    5858{
    59     float deltams = data[id].timer.GetMs();
     59    float seconds = data[id].timer.Get();
    6060
    61     data[id].history[Ticker::GetFrameNum() % ProfilerData::HISTORY] = deltams;
     61    data[id].history[Ticker::GetFrameNum() % ProfilerData::HISTORY] = seconds;
    6262    data[id].avg = 0.0f;
    6363    data[id].max = 0.0f;
  • trunk/src/ticker.cpp

    r1144 r1309  
    189189        else
    190190        {
    191             data->deltams = data->timer.GetMs();
     191            data->deltams = 1000.0f * data->timer.Get();
    192192            data->bias += data->deltams;
    193193        }
     
    397397        framems = data->bias + 200.0f; // Don't go below 5 fps
    398398    if (framems > data->bias)
    399         data->timer.WaitMs(framems - data->bias);
     399        data->timer.Wait(1e-3f * (framems - data->bias));
    400400
    401401    /* If recording, do not try to compensate for lag. */
  • trunk/src/timer.cpp

    r1173 r1309  
    6363    }
    6464
    65     float GetOrWait(float deltams, bool update)
     65    float GetOrWait(float seconds, bool update)
    6666    {
    67         float ret, towait;
     67        float secs_elapsed, secs_towait;
    6868#if defined __linux__ || defined __native_client__ || defined __APPLE__
    6969        struct timeval tv;
    7070        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);
    7373        if (update)
    7474            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));
    7878#elif defined _WIN32
    7979        LARGE_INTEGER cycles;
    8080        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);
    8383        if (update)
    8484            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));
    8888#elif defined __CELLOS_LV2__
    8989        uint64_t cycles;
    9090        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);
    9393        if (update)
    9494            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));
    9898#else
    9999        /* The crappy SDL fallback */
    100100        Uint32 ticks = SDL_GetTicks();
    101         ret = ticks - ticks0;
     101        secs_elapsed = 1e-3f * (ticks - ticks0);
    102102        if (update)
    103103            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));
    107107#endif
    108         return ret;
     108        return secs_elapsed;
    109109    }
    110110
    111     static float GetMsPerCycle()
     111    static float GetSecondsPerCycle()
    112112    {
    113113#if defined __linux__ || defined __native_client__ || defined __APPLE__
    114         return 1.0f;
     114        return 1e-3f;
    115115#elif defined _WIN32
    116116        LARGE_INTEGER tmp;
    117117        QueryPerformanceFrequency(&tmp);
    118         return 1e3f / tmp.QuadPart;
     118        return 1.f / tmp.QuadPart;
    119119#elif defined __CELLOS_LV2__
    120         return 1e3f / sys_time_get_timebase_frequency();
     120        return 1.f / sys_time_get_timebase_frequency();
    121121#else
    122         return 1.0f;
     122        return 1e-3f;
    123123#endif
    124124    }
     
    149149}
    150150
    151 float Timer::GetMs()
     151float Timer::Get()
    152152{
    153153    return data->GetOrWait(0.0f, true);
    154154}
    155155
    156 float Timer::PollMs()
     156float Timer::Poll()
    157157{
    158158    return data->GetOrWait(0.0f, false);
    159159}
    160160
    161 void Timer::WaitMs(float deltams)
     161void Timer::Wait(float seconds)
    162162{
    163     (void)data->GetOrWait(deltams, false);
     163    (void)data->GetOrWait(seconds, false);
    164164}
    165165
  • trunk/src/timer.h

    r748 r1309  
    2828    ~Timer();
    2929
    30     float GetMs();
    31     float PollMs();
    32     void WaitMs(float deltams);
     30    float Get();
     31    float Poll();
     32    void Wait(float seconds);
    3333
    3434private:
  • trunk/test/benchmark/half.cpp

    r942 r1309  
    4747
    4848        /* Copy float */
    49         timer.GetMs();
     49        timer.Get();
    5050        for (size_t i = 0; i < HALF_TABLE_SIZE; i++)
    5151            pf[i] = pf[i + 1];
    52         result[0] += timer.GetMs();
     52        result[0] += timer.Get();
    5353
    5454        /* Convert half to float (array) */
    55         timer.GetMs();
     55        timer.Get();
    5656        half::convert(pf, ph, HALF_TABLE_SIZE);
    57         result[1] += timer.GetMs();
     57        result[1] += timer.Get();
    5858
    5959        /* Convert half to float (fast) */
    60         timer.GetMs();
     60        timer.Get();
    6161        for (size_t i = 0; i < HALF_TABLE_SIZE; i++)
    6262            pf[i] = (float)ph[i];
    63         result[2] += timer.GetMs();
     63        result[2] += timer.Get();
    6464
    6565        /* Add a half to every float */
    66         timer.GetMs();
     66        timer.Get();
    6767        for (size_t i = 0; i < HALF_TABLE_SIZE; i++)
    6868            pf[i] += ph[i];
    69         result[3] += timer.GetMs();
     69        result[3] += timer.Get();
    7070
    7171        /* Copy half */
    72         timer.GetMs();
     72        timer.Get();
    7373        for (size_t i = 0; i < HALF_TABLE_SIZE; i++)
    7474            ph[i] = ph[i + 1];
    75         result[4] += timer.GetMs();
     75        result[4] += timer.Get();
    7676
    7777        /* Change sign of every half */
    78         timer.GetMs();
     78        timer.Get();
    7979        for (size_t i = 0; i < HALF_TABLE_SIZE; i++)
    8080            ph[i] = -ph[i];
    81         result[5] += timer.GetMs();
     81        result[5] += timer.Get();
    8282
    8383        /* Convert float to half (array) */
    84         timer.GetMs();
     84        timer.Get();
    8585        half::convert(ph, pf, HALF_TABLE_SIZE);
    86         result[6] += timer.GetMs();
     86        result[6] += timer.Get();
    8787
    8888        /* Convert float to half (fast) */
    89         timer.GetMs();
     89        timer.Get();
    9090        for (size_t i = 0; i < HALF_TABLE_SIZE; i++)
    9191            ph[i] = (half)pf[i];
    92         result[7] += timer.GetMs();
     92        result[7] += timer.Get();
    9393
    9494        /* Convert float to half (accurate) */
    95         timer.GetMs();
     95        timer.Get();
    9696        for (size_t i = 0; i < HALF_TABLE_SIZE; i++)
    9797            ph[i] = half::makeaccurate(pf[i]);
    98         result[8] += timer.GetMs();
     98        result[8] += timer.Get();
    9999
    100100        /* Add a float to every half */
    101         timer.GetMs();
     101        timer.Get();
    102102        for (size_t i = 0; i < HALF_TABLE_SIZE; i++)
    103103            ph[i] += pf[i];
    104         result[9] += timer.GetMs();
     104        result[9] += timer.Get();
    105105    }
    106106
     
    109109
    110110    for (size_t i = 0; i < sizeof(result) / sizeof(*result); i++)
    111         result[i] *= 1000000.0f / (HALF_TABLE_SIZE * HALF_RUNS);
     111        result[i] *= 1e9f / (HALF_TABLE_SIZE * HALF_RUNS);
    112112
    113113    Log::Info("                          ns/elem\n");
  • trunk/test/benchmark/real.cpp

    r1020 r1309  
    3737
    3838        real fib1 = 1.0, fib2 = 1.0;
    39         timer.GetMs();
     39        timer.Get();
    4040        for (size_t i = 0; i < REAL_TABLE_SIZE; i++)
    4141        {
     
    4444            fib2 = tmp;
    4545        }
    46         result[0] += timer.GetMs();
     46        result[0] += timer.Get();
    4747
    4848        real fact = 1.0;
    49         timer.GetMs();
     49        timer.Get();
    5050        for (size_t i = 0; i < REAL_TABLE_SIZE; i++)
    5151            fact = fact * real(1.0 + i);
    52         result[1] += timer.GetMs();
     52        result[1] += timer.Get();
    5353
    5454        real invfact = 1.0;
    55         timer.GetMs();
     55        timer.Get();
    5656        for (size_t i = 0; i < REAL_TABLE_SIZE; i++)
    5757            invfact = invfact / real(1.0 + i);
    58         result[2] += timer.GetMs();
     58        result[2] += timer.Get();
    5959
    60         timer.GetMs();
     60        timer.Get();
    6161        for (size_t i = 0; i < REAL_TABLE_SIZE / 128; i++)
    6262            sin(real(0.01 * i));
    63         result[3] += timer.GetMs() * 128;
     63        result[3] += timer.Get() * 128;
    6464
    65         timer.GetMs();
     65        timer.Get();
    6666        for (size_t i = 0; i < REAL_TABLE_SIZE / 128; i++)
    6767            exp((real)(int)(i - REAL_TABLE_SIZE / 256));
    68         result[4] += timer.GetMs() * 128;
     68        result[4] += timer.Get() * 128;
    6969    }
    7070
    7171    for (size_t i = 0; i < sizeof(result) / sizeof(*result); i++)
    72         result[i] *= 1000000.0f / (REAL_TABLE_SIZE * REAL_RUNS);
     72        result[i] *= 1e9f / (REAL_TABLE_SIZE * REAL_RUNS);
    7373
    7474    Log::Info("                              ns/elem\n");
  • trunk/test/benchmark/trig.cpp

    r1189 r1309  
    6565
    6666        /* Sin */
    67         timer.GetMs();
     67        timer.Get();
    6868        for (size_t i = 0; i < TRIG_TABLE_SIZE; i++)
    6969#if defined __GNUC__ && !defined __SNC__
     
    7272            pf2[i] = sinf(pf[i]);
    7373#endif
    74         result[0] += timer.GetMs();
     74        result[0] += timer.Get();
    7575
    7676        /* Fast sin */
    77         timer.GetMs();
     77        timer.Get();
    7878        for (size_t i = 0; i < TRIG_TABLE_SIZE; i++)
    7979#if defined HAVE_FASTMATH_H && !defined __native_client__
     
    8282            pf2[i] = sinf(pf[i]);
    8383#endif
    84         result[1] += timer.GetMs();
     84        result[1] += timer.Get();
    8585
    8686        /* Lol sin */
    87         timer.GetMs();
     87        timer.Get();
    8888        for (size_t i = 0; i < TRIG_TABLE_SIZE; i++)
    8989            pf2[i] = lol_sin(pf[i]);
    90         result[2] += timer.GetMs();
     90        result[2] += timer.Get();
    9191
    9292        /* Cos */
    93         timer.GetMs();
     93        timer.Get();
    9494        for (size_t i = 0; i < TRIG_TABLE_SIZE; i++)
    9595#if defined __GNUC__ && !defined __SNC__
     
    9898            pf2[i] = cosf(pf[i]);
    9999#endif
    100         result[3] += timer.GetMs();
     100        result[3] += timer.Get();
    101101
    102102        /* Fast cos */
    103         timer.GetMs();
     103        timer.Get();
    104104        for (size_t i = 0; i < TRIG_TABLE_SIZE; i++)
    105105#if defined HAVE_FASTMATH_H && !defined __native_client__
     
    108108            pf2[i] = cosf(pf[i]);
    109109#endif
    110         result[4] += timer.GetMs();
     110        result[4] += timer.Get();
    111111
    112112        /* Lol cos */
    113         timer.GetMs();
     113        timer.Get();
    114114        for (size_t i = 0; i < TRIG_TABLE_SIZE; i++)
    115115            pf2[i] = lol_cos(pf[i]);
    116         result[5] += timer.GetMs();
     116        result[5] += timer.Get();
    117117
    118118        /* Sin & cos */
    119         timer.GetMs();
     119        timer.Get();
    120120        for (size_t i = 0; i < TRIG_TABLE_SIZE; i++)
    121121        {
     
    128128#endif
    129129        }
    130         result[6] += timer.GetMs();
     130        result[6] += timer.Get();
    131131
    132132        /* Fast sin & cos */
    133         timer.GetMs();
     133        timer.Get();
    134134        for (size_t i = 0; i < TRIG_TABLE_SIZE; i++)
    135135        {
     
    142142#endif
    143143        }
    144         result[7] += timer.GetMs();
     144        result[7] += timer.Get();
    145145
    146146        /* Lol sincos */
    147         timer.GetMs();
     147        timer.Get();
    148148        for (size_t i = 0; i < TRIG_TABLE_SIZE; i++)
    149149            lol_sincos(pf[i], &pf2[i], &pf3[i]);
    150         result[8] += timer.GetMs();
     150        result[8] += timer.Get();
    151151
    152152        /* Tan */
    153         timer.GetMs();
     153        timer.Get();
    154154        for (size_t i = 0; i < TRIG_TABLE_SIZE; i++)
    155155#if defined __GNUC__ && !defined __SNC__
     
    158158            pf2[i] = tanf(pf[i]);
    159159#endif
    160         result[9] += timer.GetMs();
     160        result[9] += timer.Get();
    161161
    162162        /* Fast tan */
    163         timer.GetMs();
     163        timer.Get();
    164164        for (size_t i = 0; i < TRIG_TABLE_SIZE; i++)
    165165#if defined HAVE_FASTMATH_H && !defined __native_client__
     
    168168            pf2[i] = tanf(pf[i]);
    169169#endif
    170         result[10] += timer.GetMs();
     170        result[10] += timer.Get();
    171171
    172172        /* Lol tan */
    173         timer.GetMs();
     173        timer.Get();
    174174        for (size_t i = 0; i < TRIG_TABLE_SIZE; i++)
    175175            pf2[i] = lol_tan(pf[i]);
    176         result[11] += timer.GetMs();
     176        result[11] += timer.Get();
    177177    }
    178178
     
    182182
    183183    for (size_t i = 0; i < sizeof(result) / sizeof(*result); i++)
    184         result[i] *= 1000000.0f / (TRIG_TABLE_SIZE * TRIG_RUNS);
     184        result[i] *= 1e9f / (TRIG_TABLE_SIZE * TRIG_RUNS);
    185185
    186186    Log::Info("                              ns/elem\n");
  • trunk/test/benchmark/vector.cpp

    r1257 r1309  
    4545
    4646        /* Copy matrices */
    47         timer.GetMs();
     47        timer.Get();
    4848        for (size_t i = 0; i < MATRIX_TABLE_SIZE; i++)
    4949            pm[i] = pm[i + 1];
    50         result[0] += timer.GetMs();
     50        result[0] += timer.Get();
    5151
    5252        /* Determinant */
    53         timer.GetMs();
     53        timer.Get();
    5454        for (size_t i = 0; i < MATRIX_TABLE_SIZE; i++)
    5555            pf[i] = determinant(pm[i]);
    56         result[1] += timer.GetMs();
     56        result[1] += timer.Get();
    5757
    5858        /* Multiply matrices */
    59         timer.GetMs();
     59        timer.Get();
    6060        for (size_t i = 0; i < MATRIX_TABLE_SIZE; i++)
    6161            pm[i] *= pm[i + 1];
    62         result[2] += timer.GetMs();
     62        result[2] += timer.Get();
    6363
    6464        /* Add matrices */
    65         timer.GetMs();
     65        timer.Get();
    6666        for (size_t i = 0; i < MATRIX_TABLE_SIZE; i++)
    6767            pm[i] += pm[i + 1];
    68         result[3] += timer.GetMs();
     68        result[3] += timer.Get();
    6969
    7070        /* Invert matrix */
    71         timer.GetMs();
     71        timer.Get();
    7272        for (size_t i = 0; i < MATRIX_TABLE_SIZE; i++)
    7373            pm[i] = inverse(pm[i]);
    74         result[4] += timer.GetMs();
     74        result[4] += timer.Get();
    7575    }
    7676
     
    7979
    8080    for (size_t i = 0; i < sizeof(result) / sizeof(*result); i++)
    81         result[i] *= 1000000.0f / (MATRIX_TABLE_SIZE * MATRIX_RUNS);
     81        result[i] *= 1e9f / (MATRIX_TABLE_SIZE * MATRIX_RUNS);
    8282
    8383    Log::Info("                          ns/elem\n");
Note: See TracChangeset for help on using the changeset viewer.