diff options
author | Sam Lantinga <slouken@libsdl.org> | 2011-03-25 14:45:04 -0700 |
---|---|---|
committer | Sam Lantinga <slouken@libsdl.org> | 2011-03-25 14:45:04 -0700 |
commit | 85ad17e7d65e16a54fa254a91dfee6c1d543a37f (patch) | |
tree | 7e3a419837f49f8af370da9d831f5ce72bd05017 /test/testtimer.c | |
parent | 98e5ddb37dc0c89a787b19b617a261d5d6da8951 (diff) |
Added high resolution timing API: SDL_GetPerformanceCounter(), SDL_GetPerformanceFrequency()
Diffstat (limited to 'test/testtimer.c')
-rw-r--r-- | test/testtimer.c | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/test/testtimer.c b/test/testtimer.c index f58efbbd..c2d1573a 100644 --- a/test/testtimer.c +++ b/test/testtimer.c @@ -29,8 +29,9 @@ callback(Uint32 interval, void *param) int main(int argc, char *argv[]) { - int desired; + int i, desired; SDL_TimerID t1, t2, t3; + Uint64 start, now; if (SDL_Init(SDL_INIT_TIMER) < 0) { fprintf(stderr, "Couldn't initialize SDL: %s\n", SDL_GetError()); @@ -85,6 +86,15 @@ main(int argc, char *argv[]) SDL_RemoveTimer(t2); SDL_RemoveTimer(t3); + start = SDL_GetPerformanceCounter(); + for (i = 0; i < 1000000; ++i) { + ticktock(0); + } + now = SDL_GetPerformanceCounter(); + printf("1 million iterations of ticktock took %f ms\n", (double)((now - start)*1000) / SDL_GetPerformanceFrequency()); + SDL_Quit(); return (0); } + +/* vi: set ts=4 sw=4 expandtab: */ |