惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

W
WeLiveSecurity
The GitHub Blog
The GitHub Blog
Engineering at Meta
Engineering at Meta
Microsoft Azure Blog
Microsoft Azure Blog
The Register - Security
The Register - Security
Stack Overflow Blog
Stack Overflow Blog
博客园 - 三生石上(FineUI控件)
T
Threat Research - Cisco Blogs
S
SegmentFault 最新的问题
V2EX - 技术
V2EX - 技术
Hacker News: Ask HN
Hacker News: Ask HN
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
P
Proofpoint News Feed
J
Java Code Geeks
Microsoft Security Blog
Microsoft Security Blog
M
MIT News - Artificial intelligence
AI
AI
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
P
Proofpoint News Feed
Hacker News - Newest:
Hacker News - Newest: "LLM"
B
Blog
N
News and Events Feed by Topic
N
News | PayPal Newsroom
Google DeepMind News
Google DeepMind News
酷 壳 – CoolShell
酷 壳 – CoolShell
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
WordPress大学
WordPress大学
C
Cybersecurity and Infrastructure Security Agency CISA
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
博客园 - 【当耐特】
U
Unit 42
腾讯CDC
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
The Cloudflare Blog
H
Help Net Security
Recent Announcements
Recent Announcements
P
Privacy & Cybersecurity Law Blog
IT之家
IT之家
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
Security Archives - TechRepublic
Security Archives - TechRepublic
L
LINUX DO - 热门话题
Martin Fowler
Martin Fowler
MongoDB | Blog
MongoDB | Blog
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
H
Heimdal Security Blog
博客园 - 聂微东
S
Securelist
大猫的无限游戏
大猫的无限游戏
Cloudbric
Cloudbric
Cisco Talos Blog
Cisco Talos Blog

博客园 - 吾非无心

MSB4019 找不到导入的项目“C:\Users\...\AppData\Local\QtMsBuild\vs-debugtools\qt_import.props” - 吾非无心 - 博客园 类/结构最后一个成员为类(string)时可能会出现“堆损坏”(HEAP CORRUPTION DETECTED)错误 GCC在C语言中内嵌汇编 asm __volatile__ QT删除python中的单行注释 double转int QJson 存储(u)longlong有问题 QT QPixmap QImage内存泄漏 QMetaObject::connectSlotsByName: No matching signal for QT数据库连接管理类 QT多重继承带来的问题及解决办法,记录备查 QT6 源码编译Win32 x86 stack smashing detected 莫名其妙的错误 strdump的问题 再加一个realloc的问题 linux下简单封装读写锁 codeblocks下libacl配置 centos8 安装、配置redis6 pyftpdlib中文乱码的解决之道 CentOS8让uwsgi开机自动启动django(无需登录,无需手动) libevent学习一
vc++高精度计时sleep
吾非无心 · 2021-09-06 · via 博客园 - 吾非无心
LARGE_INTEGER high_precision_sleep(LARGE_INTEGER preTime, unsigned long long   sleepTime) {
    LARGE_INTEGER t;
    QueryPerformanceCounter(&t);
    
    while(t.QuadPart-preTime.QuadPart<sleepTime)QueryPerformanceCounter(&t);
    //printf("sleepTime=%d\n", t.QuadPart-preTime.QuadPart);//调试时用来观察每次暂停时间。一般应略有不同才正确
    /*//这种方式与直接返回t精度差不多,但多了一个运算,划不来
preTime.QuadPart += sleepTime; return preTime;*/ return t; }

  使用方法:

LARGE_INTEGER freq,t0,t1,t3;

QueryPerformanceFrequency(&freq);//频率   计数/秒

//当前频率 TIMES_PER_SECOND 下间隔的计数
auto SLEEP_COUNT = freq.QuadPart / TIMES_PER_SECOND;

QueryPerformanceCounter(&t0);
QueryPerformanceCounter(&t3);
for (int i = 0; i < number; i++) {

   //do something

   srand(t3.LowPart);//srand()函数产生一个以当前时间开始的随机种子
  Sleep(rand() %20 );//TIMES_PER_SECOND=30,理论上每次Sleep(33.33ms),但不能Sleep(rand()%30),因为Sleep精度问题,可能实际上超过

  //BitBlt(dcMem, 0, 0, 1920, 1080, dcScreen, 0, 0, SRCCOPY);

  t3=high_precision_sleep(t3, SLEEP_COUNT);

}

QueryPerformanceCounter(&t1);

cout << "执行 "<< number << " 次, 耗时 " << (((t1.QuadPart - t0.QuadPart) * 1000000) / freq.QuadPart)<< " 微秒" << std::endl;

当TIMES_PER_SECOND=30,number=500时,理论耗时:

实际耗时:耗时 16668737 微秒、耗时 16668737 微秒、耗时 16667480 微秒...每次相差不大,在1ms左右