pad.mattdiesel.co.uk

Snippet - AutoIt timers using C++11 Chromo

AutoIt timers using C++11 Chromo (C++)

Replicate AutoIt's timer functions using the chromo library
Created 2014-04-08 19:54:15.329860 by Matt.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#include <iostream>
#include <chrono>
 
typedef std::chrono::high_resolution_clock _timerClock;
typedef long long __int64;
 
 
__int64 TimerInit() {
    _timerClock::time_point t1 = _timerClock::now();
 
	return __int64(std::chrono::duration_cast<std::chrono::nanoseconds>
			(t1.time_since_epoch()).count());
}
 
double TimerDiff(__int64 start) {
	_timerClock::time_point t1 = _timerClock::now();
 
	return double(__int64(std::chrono::duration_cast<std::chrono::nanoseconds>
			(t1.time_since_epoch()).count()) - start) / 1000000;
}
 
 
 
int main() {
	auto MyTimer = TimerInit();
 
	std::cout << MyTimer << std::endl;
 
	sleep(2);
 
	std::cout << TimerDiff(MyTimer) << std::endl;
 
	return 0;
}