X-Git-Url: https://git.saurik.com/apple/system_cmds.git/blobdiff_plain/1a7e3f61d38d679bba59130891c2031b5a0092b6..bd6521f0fc816ab056bc71376f9706a69b3b52c1:/CPPUtil/UtilTimer.cpp?ds=inline diff --git a/CPPUtil/UtilTimer.cpp b/CPPUtil/UtilTimer.cpp new file mode 100644 index 0000000..b285565 --- /dev/null +++ b/CPPUtil/UtilTimer.cpp @@ -0,0 +1,31 @@ +// +// UtilTimer.cpp +// CPPUtil +// +// Created by James McIlree on 10/9/13. +// Copyright (c) 2013 Apple. All rights reserved. +// + +#include "CPPUtil.h" + +BEGIN_UTIL_NAMESPACE + +static mach_timebase_info_data_t timebase_info; + +Timer::Timer(const char* message) : _message(message) { + // C++ guarantees that static variable initialization is thread safe. + // We don't actually care what the returned value is, we just want to init timebase_info + // The pragma prevents spurious warnings. + static kern_return_t blah = mach_timebase_info(&timebase_info); +#pragma unused(blah) + + _start = AbsTime::now(); // Do this after the initialization check. +} + +Timer::~Timer() +{ + _end = AbsTime::now(); + printf("%s: %5.5f seconds\n", _message.c_str(), (double)(_end - _start).nano_time().value() / (double)NANOSECONDS_PER_SECOND); +} + +END_UTIL_NAMESPACE