High-resolution timer for C++
来源:互联网 发布:ubuntu kylin什么意思 编辑:程序博客网 时间:2024/06/06 13:23
High-resolution timer for C++
27 Dec 2011 4:01 PM
Howdy ho! My name is Simon Wybranski, I am a developer on the C++ AMP team!
In this blog post I am going to present a high-resolution timer for measuring the performance of C++ AMP algorithms. There is nothing specific in it to C++ AMP, so it can be used to measure elapsed time of your PPL algorithms or any other C++ code.
Listing of timer.h:
1: #pragma once
2: #include <windows.h>
3:
4: struct Timer
5: {
6: void Start()
7: {
8: QueryPerformanceCounter(&m_start);
9: }
10:
11: void Stop()
12: {
13: QueryPerformanceCounter(&m_stop);
14: }
15:
16: // Returns elapsed time in milliseconds (ms)
17: double Elapsed()
18: {
19: return (m_stop.QuadPart - m_start.QuadPart - m_overhead) \
20: * 1000.0 / m_freq.QuadPart;
21: }
22:
23: private:
24:
25: // Returns the overhead of the timer in ticks
26: static LONGLONG GetOverhead()
27: {
28: Timer t;
29: t.Start();
30: t.Stop();
31: return t.m_stop.QuadPart - t.m_start.QuadPart;
32: }
33:
34: LARGE_INTEGER m_start;
35: LARGE_INTEGER m_stop;
36: static LARGE_INTEGER m_freq;
37: static LONGLONG m_overhead;
38: };
Listing of timer.cpp:
1: #include "timer.h"
2:
3: // Initialize the resolution of the timer
4: LARGE_INTEGER Timer::m_freq = \
5: (QueryPerformanceFrequency(&Timer::m_freq), Timer::m_freq);
6:
7: // Calculate the overhead of the timer
8: LONGLONG Timer::m_overhead = Timer::GetOverhead();
Snippet showing the usage:
1: Timer t;
2: t.Start();
3: // Your algorithm goes here
4: t.Stop();
5:
6: std::cout << t.Elapsed() << " ms" << std::endl;
Enjoy!!
- High-resolution timer for C++
- High-Resolution Timer
- High-Resolution Timer
- High Resolution Timer内核高精度时钟
- 高精度计时器(High Resolution Timer)
- 关于Linux的 High-Resolution Timer
- Reading notes about High-resolution timer managememt on linux
- RefineNet: Multi-Path Refinement Networks for High-Resolution Semantic Segmentation
- High-Resolution Timers
- PCL :Supporting High Resolution Printing
- Handling large/high resolution images
- Mobile Web in High Resolution
- [Paper note] RefineNet: Multi-Path Refinement Networks for High-Resolution Semantic Segmentation
- [论文分享]RefineNet: Multi-Path Refinement Networks for High-Resolution Semantic Segmentation
- Transferring Deep Convolutional Neural Networks for the Scene Classification of High-Resolution Remo
- Training Deep Convolutional Neural Networks for Land–Cover Classification of High-Resolution Imagery
- 【ICNet】ICNet for Real-Time Semantic Segmentation on High-Resolution Images
- [深度学习论文笔记][CVPR 17]RefineNet: Multi-Path Refinement Networks for High-Resolution Semantic
- 模式识别之我见
- C++ AMP: Any optimization ways in memory transfer in AMP?
- 为什么VS提示SurfFeatureDetector不是cv的成员函数
- hdu 4751 Divide Groups (两种解法 1.bfs 2.dfs)
- 《C++编程实战》学习笔记
- High-resolution timer for C++
- 龙乡设置县前后社会纵横
- 基本数据类型对象包装类
- LeetCode | Balanced Binary Tree
- 2013-ACMICPC Nanjing Online 02 Parade Show
- ecshop中的浏览历史
- LINUX学习[2]---ubuntu12.04 无线网卡配置
- 修改Oracle数据库的连接数
- c++基础知识