Changeset 765


Ignore:
Timestamp:
May 2, 2011, 1:18:41 PM (9 years ago)
Author:
sam
Message:

timer: avoid useless system calls in the Timer constructor.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/timer.cpp

    r763 r765  
    4949        gettimeofday(&tv0, NULL);
    5050#elif defined _WIN32
    51         LARGE_INTEGER tmp;
    52         QueryPerformanceFrequency(&tmp);
    53         ms_per_cycle = 1e3f / tmp.QuadPart;
    5451        QueryPerformanceCounter(&cycles0);
    5552#elif defined __CELLOS_LV2__
    56         ms_per_cycle = 1e3f / sys_time_get_timebase_frequency();
    5753        SYS_TIMEBASE_GET(cycles0);
    5854#else
     
    7874        LARGE_INTEGER cycles;
    7975        QueryPerformanceCounter(&cycles);
     76        static float ms_per_cycle = GetMsPerCycle();
    8077        ret = ms_per_cycle * (cycles.QuadPart - cycles0.QuadPart);
    8178        if (update)
     
    8784        uint64_t cycles;
    8885        SYS_TIMEBASE_GET(cycles);
     86        static float ms_per_cycle = GetMsPerCycle();
    8987        ret = ms_per_cycle * (cycles - cycles0);
    9088        if (update)
     
    106104    }
    107105
     106    static float GetMsPerCycle()
     107    {
     108#if defined __linux__ || defined __APPLE__
     109        return 1.0f;
     110#elif defined _WIN32
     111        LARGE_INTEGER tmp;
     112        QueryPerformanceFrequency(&tmp);
     113        return = 1e3f / tmp.QuadPart;
     114#elif defined __CELLOS_LV2__
     115        return 1e3f / sys_time_get_timebase_frequency();
     116#else
     117        return 1.0f;
     118#endif
     119    }
     120
    108121#if defined __linux__ || defined __APPLE__
    109122    struct timeval tv0;
    110123#elif defined _WIN32
    111     float ms_per_cycle;
    112124    LARGE_INTEGER cycles0;
    113125#elif defined __CELLOS_LV2__
    114     float ms_per_cycle;
    115126    uint64_t cycles0;
    116127#else
Note: See TracChangeset for help on using the changeset viewer.