Monk Posted December 3, 2008 Share Posted December 3, 2008 /*- * Copyright (c) 2006, 2007, 2008 Gary Stanley (gary@summit-servers.com) * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ #include <stdio.h> #include "stdafx.h" #include "windows.h" #pragma comment ( lib, "winmm.lib" ) int main(void) { /* One of the major problems with FPS calculation is cache line bouncing/cache stalls due to prefetching There is no magic bullet to make things work. They either work, or they don't. */ const int count = 512; printf("This program estimates gameserver FPS and displays the results.\n"); printf("The results of this program are rounded to the nearest int / 1000\n"); printf("\n"); timeBeginPeriod(1); /* Needed for low latency Sleeps */ int its = 0; long cur = 0, last = timeGetTime(); while (its < count) { cur = timeGetTime(); if (cur != last) { last = cur; its++; } } printf("Testing Sleep(1) granularity :\n"); long first = timeGetTime(); cur = first; last = first; for (int n=0; n<count; n++) { Sleep(1); cur = timeGetTime(); printf("Wakeup Latency: %dms Estimated Maximum FPS: %d\n", cur-last, (1000 / (cur-last) ) ); last = cur; } getchar(); } This more or less shows how long a sleep(1) really sleeps. It is currently rounded to the nearest hundreth of a MS, and it rounds down or up depending on a number of things. Anyways, I used this for quite a few years to debug hardware to see why FPS/tickrate wouldn't remain the same even though there was nothing running. This has other uses, too, if you want to figure out if a machine has too many servers fighting for a scheduler quantum... I'm currently working on something that shows how long a sleep(1) really takes, down to the microsecond with rdtsc and some other non-windows tricks.FPS estimator.zip Link to comment Share on other sites More sharing options...
Derek Posted December 3, 2008 Share Posted December 3, 2008 Thanks Monk=/ Link to comment Share on other sites More sharing options...
Monk Posted December 3, 2008 Author Share Posted December 3, 2008 oops. try this one instead..FPS estimator.zip Link to comment Share on other sites More sharing options...
Monk Posted December 3, 2008 Author Share Posted December 3, 2008 On windows 2003 sometimes the sleep latency will drop down to about 1.95, so its rounding the value down. until i rewrite the functions its more or less generally estimated .. Link to comment Share on other sites More sharing options...
Steven Crothers Posted December 21, 2008 Share Posted December 21, 2008 Nice, very accurate. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.