Add simple time functions

This commit is contained in:
Danny Robson 2011-08-29 15:28:11 +10:00
parent e816983869
commit 91daeb332f
3 changed files with 64 additions and 0 deletions

View File

@ -31,6 +31,7 @@ UTIL_INCLUDE = \
stream.hpp \ stream.hpp \
string.hpp \ string.hpp \
si.hpp \ si.hpp \
time.hpp \
types.hpp \ types.hpp \
vector.hpp \ vector.hpp \
version.hpp version.hpp
@ -56,6 +57,7 @@ UTIL_FILES = \
stream.cpp \ stream.cpp \
string.cpp \ string.cpp \
si.cpp \ si.cpp \
time.cpp \
types.cpp \ types.cpp \
vector.cpp \ vector.cpp \
version.cpp version.cpp

33
time.cpp Normal file
View File

@ -0,0 +1,33 @@
/*
* This file is part of libgim.
*
* libgim is free software: you can redistribute it and/or modify it under the
* terms of the GNU General Public License as published by the Free Software
* Foundation, either version 3 of the License, or (at your option) any later
* version.
*
* libgim is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License
* along with libgim. If not, see <http://www.gnu.org/licenses/>.
*
* Copyright 2010 Danny Robson <danny@blubinc.net>
*/
#include "time.hpp"
#include <ctime>
using namespace util;
uint64_t
util::nanoseconds (void) {
struct timespec t;
clock_gettime (CLOCK_REALTIME, &t);
return t.tv_sec * 1000000000 + t.tv_nsec;
}

29
time.hpp Normal file
View File

@ -0,0 +1,29 @@
/*
* This file is part of libgim.
*
* libgim is free software: you can redistribute it and/or modify it under the
* terms of the GNU General Public License as published by the Free Software
* Foundation, either version 3 of the License, or (at your option) any later
* version.
*
* libgim is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License
* along with libgim. If not, see <http://www.gnu.org/licenses/>.
*
* Copyright 2010 Danny Robson <danny@blubinc.net>
*/
#ifndef __UTIL_TIME_HPP
#define __UTIL_TIME_HPP
#include <cstdint>
namespace util {
uint64_t nanoseconds (void);
}
#endif // __UTIL_TIME_HPP