]> git.saurik.com Git - apple/system_cmds.git/blob - CPPUtil/UtilTimer.cpp
b285565de0b733e5ecbac05bd495f1a7c7fe4f99
[apple/system_cmds.git] / CPPUtil / UtilTimer.cpp
1 //
2 // UtilTimer.cpp
3 // CPPUtil
4 //
5 // Created by James McIlree on 10/9/13.
6 // Copyright (c) 2013 Apple. All rights reserved.
7 //
8
9 #include "CPPUtil.h"
10
11 BEGIN_UTIL_NAMESPACE
12
13 static mach_timebase_info_data_t timebase_info;
14
15 Timer::Timer(const char* message) : _message(message) {
16 // C++ guarantees that static variable initialization is thread safe.
17 // We don't actually care what the returned value is, we just want to init timebase_info
18 // The pragma prevents spurious warnings.
19 static kern_return_t blah = mach_timebase_info(&timebase_info);
20 #pragma unused(blah)
21
22 _start = AbsTime::now(); // Do this after the initialization check.
23 }
24
25 Timer::~Timer()
26 {
27 _end = AbsTime::now();
28 printf("%s: %5.5f seconds\n", _message.c_str(), (double)(_end - _start).nano_time().value() / (double)NANOSECONDS_PER_SECOND);
29 }
30
31 END_UTIL_NAMESPACE