博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
jrtlib 时间测试
阅读量:7052 次
发布时间:2019-06-28

本文共 2768 字,大约阅读时间需要 9 分钟。

代码:

#include "rtptimeutilities.h"#include 
#include
using namespace std;using namespace jrtplib;int main(void){ double times[] = { 1.2, -2.3, 0, 3.999999 }; for (int i = 0 ; i < sizeof(times)/sizeof(double) ; i++) { RTPTime t(times[i]); cout << "Double: " << times[i] << endl; cout << "Seconds: " << t.GetSeconds() << endl; cout << "Microseconds: " << t.GetMicroSeconds() << endl; cout << endl; } int32_t secsAndMuSecs[][2] = { { 1, 3000}, {-2, 200}, {0, 0}, {-2, 999999} }; for (int i = 0 ; i < sizeof(secsAndMuSecs)/(2*sizeof(int32_t)) ; i++) { RTPTime t(secsAndMuSecs[i][0], secsAndMuSecs[i][1]); cout << "Input Seconds: " << secsAndMuSecs[i][0] << endl; cout << "Input Microseconds: " << secsAndMuSecs[i][1] << endl; cout << "Output Seconds: " << t.GetSeconds() << endl; cout << "Output Microseconds: " << t.GetMicroSeconds() << endl; cout << "Output Double: " << t.GetDouble() << endl; cout << endl; } for (int i = 0 ; i < 10 ; i++) { RTPTime now = RTPTime::CurrentTime(); fprintf(stderr, "%10u.%06d\n", (uint32_t)now.GetSeconds(), now.GetMicroSeconds()); RTPTime::Wait(RTPTime(1)); } return 0;}

  运行结果:

/timetest

Double: 1.2
Seconds: 1
Microseconds: 200000

Double: -2.3

Seconds: -2
Microseconds: 300000

Double: 0

Seconds: 0
Microseconds: 0

Double: 4

Seconds: 3
Microseconds: 999999

Input Seconds: 1

Input Microseconds: 3000
Output Seconds: 1
Output Microseconds: 3000
Output Double: 1.003

Input Seconds: -2

Input Microseconds: 200
Output Seconds: -2
Output Microseconds: 200
Output Double: -2.0002

Input Seconds: 0

Input Microseconds: 0
Output Seconds: 0
Output Microseconds: 0
Output Double: 0

Input Seconds: -2

Input Microseconds: 999999
Output Seconds: -2
Output Microseconds: 999999
Output Double: -3

1541561350.472532

1541561351.473606
1541561352.474346
1541561353.474663
1541561354.475759
1541561355.476676
1541561356.477701
1541561357.478725
1541561358.479587
1541561359.480622

有关函数的源码:

double GetDouble() const                                                                                { return (((double)sec)+(((double)microsec)/1000000.0)); }inline RTPTime::RTPTime(double t)   {           sec = (uint32_t)t;              double t2 = t-((double)sec);           t2 *= 1000000.0;           microsec = (uint32_t)t2;   } RTPTime(uint32_t seconds, uint32_t microseconds)                                                { sec = seconds; microsec = microseconds; }              uint32_t GetSeconds() const                                                                             { return sec; }              uint32_t GetMicroSeconds() const                                                                { return microsec; }

 

转载于:https://www.cnblogs.com/hgstudy/p/9921904.html

你可能感兴趣的文章
【BZOJ】1415 [Noi2005]聪聪和可可 期望DP+记忆化搜索
查看>>
android 7.1 调用相机崩溃解决办法
查看>>
等待时间的三种方式以及解释
查看>>
Arduino语音天气预报(一)
查看>>
转 廖雪峰 urllib
查看>>
直播源码有哪两种开发模式?
查看>>
访问控制符
查看>>
Android studio修改字体(font)大小(size)
查看>>
------第二节-----------------第二讲----单链表的基本操作---------
查看>>
iOS 百度地图大头针使用
查看>>
1118: 零起点学算法25——求两点之间的距离
查看>>
delegate代理设计模式
查看>>
花10分钟搞懂开源框架吧 - 【NancyFx.Net】
查看>>
busybox的使用
查看>>
GridView(网格视图)+MotionEvent(触控事件)实现可以拖动排序的网格图
查看>>
jq实现全选或者全不选
查看>>
牛人博客
查看>>
linux笔记_20150825_linux有什么好处
查看>>
各种实用工具的使用 学习
查看>>
MarkLight
查看>>