🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.nativeapi
Article #11156

Re: Finegrain Sleep

#11156
From: Benjamin Pratt
Date: Tue, 24 Feb 2004 03:55
83 lines
3101 bytes
> How did you take such measures? I mean, which function did
> you use?

this is the code I used. Feel free to shoot holes :)

#include <iostream>
#include <set>
#include <algorithm>
#include <windows.h>
#include <cstdlib>

bool operator<(const FILETIME& ft1, const FILETIME& ft2)
{
   ULARGE_INTEGER ul1, ul2;
   memcpy(&ul1, &ft1, sizeof(FILETIME));
   memcpy(&ul2, &ft2, sizeof(FILETIME));
   return ul1.QuadPart < ul2.QuadPart;
}

void print(FILETIME& filetime)
{
   SYSTEMTIME st;
   FileTimeToSystemTime(&filetime, &st);

   std::cout << st.wMinute << ':' << st.wSecond << '.' << st.wMilliseconds
<< std::endl;
}

void test2()
{
   LARGE_INTEGER freq;
   QueryPerformanceFrequency(&freq);
   const int calls = 100000;

   FILETIME ft;
   int i;
   LARGE_INTEGER FtStart, FtEnd;
   QueryPerformanceCounter(&FtStart);
   for(i = 0; i < calls; ++i)
      GetSystemTimeAsFileTime(&ft);
   QueryPerformanceCounter(&FtEnd);

   DWORD tc;
   LARGE_INTEGER TcStart, TcEnd;
   QueryPerformanceCounter(&TcStart);
   for(i = 0; i < calls; ++i)
      tc = GetTickCount();
   QueryPerformanceCounter(&TcEnd);


   double FtLatency = (FtEnd.QuadPart - FtStart.QuadPart)
         / double(freq.QuadPart) / double(calls);
   double TcLatency = (TcEnd.QuadPart - TcStart.QuadPart)
         / double(freq.QuadPart) / double(calls);

   std::cout << "Filetime: " << FtLatency << std::endl;
   std::cout << "TickCount: " << TcLatency << std::endl;

}


int main()
{

   std::set<FILETIME> timestamps;

   int i = 0;
   DWORD start = GetTickCount();
   while(GetTickCount() - start < 1000)
   {
      FILETIME ft;
      GetSystemTimeAsFileTime(&ft);
      timestamps.insert(ft);
   }


   std::cout << timestamps.size() << " records" << std::endl;
   std::for_each(timestamps.begin(), timestamps.end(), print);

   test2();

   return 0;
}
Technical Details
Message-ID: <403acaa5@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!news.maxwell.syr.edu!newsfeed.icl.net!newsfeed.fjserv.net!newsfeed.freenet.de!eusc.inter.net!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail
References: <4033629c$1@newsgroups.borland.com> <40336c3f@newsgroups.borland.com> <40349ac7@newsgroups.borland.com> <4034d0ba@newsgroups.borland.com> <4034ecd4$1@newsgroups.borland.com> <4035bee9@newsgroups.borland.com> <40365c30$1@newsgroups.borland.com> <4039bbb9@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 10cc67,fed9196afef30d83
X-Google-Attributes: gid10cc67,public
X-Google-ArrivalTime: 2004-02-23 20:09:38 PST
From: "Benjamin Pratt" <benjamin.pratt.getridofthis@verizon.net>
Newsgroups: borland.public.cppbuilder.nativeapi
References: <4033629c$1@newsgroups.borland.com> <40336c3f@newsgroups.borland.com> <40349ac7@newsgroups.borland.com> <4034d0ba@newsgroups.borland.com> <4034ecd4$1@newsgroups.borland.com> <4035bee9@newsgroups.borland.com> <40365c30$1@newsgroups.borland.com> <4039bbb9@newsgroups.borland.com>
Subject: Re: Finegrain Sleep
Date: Mon, 23 Feb 2004 19:55:50 -0800
Lines: 85
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
NNTP-Posting-Host: 24.130.93.201
Message-ID: <403acaa5@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1077594789 24.130.93.201 (23 Feb 2004 19:53:09 -0800)
Path: arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!news.maxwell.syr.edu!newsfeed.icl.net!newsfeed.fjserv.net!newsfeed.freenet.de!eusc.inter.net!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail