⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 timing.cxx

📁 pwlib源码库
💻 CXX
字号:
/* * timing.cxx * * Sample program to test PWLib PAdaptiveDelay. * * Portable Windows Library * * Copyright (c) 2003 Roger Hardiman * * The contents of this file are subject to the Mozilla Public License * Version 1.0 (the "License"); you may not use this file except in * compliance with the License. You may obtain a copy of the License at * http://www.mozilla.org/MPL/ * * Software distributed under the License is distributed on an "AS IS" * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See * the License for the specific language governing rights and limitations * under the License. * * The Original Code is Portable Windows Library. * * The Initial Developer of the Original Code is Roger Hardiman * * $Log: timing.cxx,v $ * Revision 1.3  2004/05/18 12:47:38  rjongbloed * Added time, time interval and timer test/demonstration code * * Revision 1.2  2004/05/18 12:25:18  rjongbloed * Added time, time interval and timer test/demonstration code * * Revision 1.1  2003/02/19 14:10:11  rogerh * Add a program to test PAdaptiveDelay * * * */#include <ptlib.h>#include <ptclib/delaychan.h>/* * The main program class */class TimingTest : public PProcess{  PCLASSINFO(TimingTest, PProcess)  public:    void Main();};PCREATE_PROCESS(TimingTest);#define TEST_TIME(t) cout << t << " => " << PTime(t) << '\n'// The main programvoid TimingTest::Main(){  cout << "Timing Test Program\n" << endl;  PTime now;  cout << "Time is now " << now.AsString("h:m:s.u d/M/y") << "\n"          "Time is now " << now.AsString("yyyy/MM/dd h:m:s.uuuu") << "\n"          "Time is now " << now.AsString("MMM/d/yyyyy w h:m:sa") << "\n"          "Time is now " << now.AsString("wwww d/M/yyy h:m:s.uu") << "\n"          "Time is now " << now.AsString("www d/MMMM/yy h:m:s.uuu") << endl;  cout << "\nTesting time string conversion" << endl;  TEST_TIME("20010203T1234Z");  TEST_TIME("20010203T1234");  TEST_TIME("20010203T0034");  TEST_TIME("20010203T10034");  TEST_TIME("20010203T123456+1100");  TEST_TIME("20010203T000056");  TEST_TIME("20010203T123456");  TEST_TIME("2001-02-03 T 12:34:56");  TEST_TIME("5/03/1999 12:34:56");  TEST_TIME("15/06/1999 12:34:56");  TEST_TIME("15/06/01 12:34:56 PST");  TEST_TIME("5/06/02 12:34:56");  TEST_TIME("5/23/1999 12:34am");  TEST_TIME("5/23/00 12:34am");  TEST_TIME("1999/23/04 12:34:56");  TEST_TIME("Mar 3, 1999 12:34pm");  TEST_TIME("3 Jul 2004 12:34pm");  TEST_TIME("12:34:56 5 December 1999");  TEST_TIME("10 minutes ago");  TEST_TIME("2 weeks");  cout << "\nTesting time interval arithmetic" << endl;  PTime then("1 month ago");  PTimeInterval elapsed = now - then;  cout << "Now=" << now << "\n"          "Then=" << then << "\n"          "Elapsed=" << elapsed << "\n"          "Milliseconds=" << elapsed.GetMilliSeconds() << "\n"          "Seconds=" << elapsed.GetSeconds() << "\n"          "Minutes=" << elapsed.GetMinutes() << "\n"          "Hours=" << elapsed.GetHours() << "\n"          "Days=" << elapsed.GetDays() << endl;  then += PTimeInterval(0,0,0,0,30);  cout << "Then plus 30 days=" << then << endl;  cout << "\nTesting timer resolution, reported as " << PTimer::Resolution() << "ms" << endl;  time_t oldSec = time(NULL);   // Wait for second boundary  while (oldSec == time(NULL))    ;  oldSec++;  PTimeInterval newTick = PTimer::Tick();  PTimeInterval oldTick = newTick;  unsigned count = 0;  while (oldSec == time(NULL)) {  // For one full second    while (newTick == oldTick)      newTick = PTimer::Tick();    oldTick = newTick;    count++;                      // Count the changes in tick  } ;  cout << "Actual resolution is " << 1000000/count << "us" << endl;  oldTick = 123456;  cout << "TimeInterval output: \"" << setw(15) << newTick << '"' << endl;  cout << "TimeInterval output: \"" << setw(15) << oldTick << '"' << endl;  int p;  for (p = 3; p < 10; p++)    cout << "TimeInterval output: " << p << " \""           << setiosflags(ios::scientific)           << setw(p) << setprecision(2) << oldTick           << resetiosflags(ios::scientific) << '"' << endl;  for (p = 3; p < 20; p++)    cout << "TimeInterval output: " << p << " \""           << setw(p) << setprecision(2) << oldTick << '"' << endl;  cout << "\nTesting sleep function" << endl;  PTime start_time1;  PINDEX loop;  for(loop = 0; loop<10; loop++) {    Sleep(10000);    PTime now1;    cout << now1-start_time1 << endl;  }  PTime end_time1;  cout << "The first loop took "<< end_time1-start_time1 << " milliseconds." << endl;  cout << "\nTesting adaptive delay function" << endl;  PAdaptiveDelay delay;  PTime start_time2;  for(loop = 0; loop<10; loop++) {    delay.Delay(10);    PTime now2;    cout << now2-start_time2 << endl;  }  PTime end_time2;  cout << "The second loop took "<< end_time2-start_time2 << " milliseconds." << endl;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -