diff options
author | Jörg Frings-Fürst <debian@jff.email> | 2025-03-19 15:41:36 +0100 |
---|---|---|
committer | Jörg Frings-Fürst <debian@jff.email> | 2025-03-19 15:41:36 +0100 |
commit | 018e1ba581ec6f01f069a45ec4cf89f152b44d5f (patch) | |
tree | 0e7dda4bb693a6714066fbe5efcd2f24ff7c1a65 /xsd/examples/cxx/parser/performance/time.cxx | |
parent | 1c188393cd2e271ed2581471b601fb5960777fd8 (diff) |
remerge
Diffstat (limited to 'xsd/examples/cxx/parser/performance/time.cxx')
-rw-r--r-- | xsd/examples/cxx/parser/performance/time.cxx | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/xsd/examples/cxx/parser/performance/time.cxx b/xsd/examples/cxx/parser/performance/time.cxx new file mode 100644 index 0000000..aca5c74 --- /dev/null +++ b/xsd/examples/cxx/parser/performance/time.cxx @@ -0,0 +1,46 @@ +// file : examples/cxx/parser/performance/time.cxx +// copyright : not copyrighted - public domain + +#include "time.hxx" + +#if defined (WIN32) || defined (__WIN32__) +# define WIN32_LEAN_AND_MEAN +# include <windows.h> // GetSystemTimeAsFileTime +#else +# include <time.h> // gettimeofday +# include <sys/time.h> // timeval +#endif + +#include <ostream> // std::ostream +#include <iomanip> // std::setfill, std::setw + +namespace os +{ + time:: + time () + { +#if defined (WIN32) || defined (__WIN32__) + FILETIME ft; + GetSystemTimeAsFileTime (&ft); + unsigned long long v ( + ((unsigned long long) (ft.dwHighDateTime) << 32) + ft.dwLowDateTime); + + sec_ = static_cast<unsigned long> (v / 10000000ULL); + nsec_ = static_cast<unsigned long> ((v % 10000000ULL) * 100); +#else + timeval tv; + if (gettimeofday(&tv, 0) != 0) + throw failed (); + + sec_ = static_cast<unsigned long> (tv.tv_sec); + nsec_ = static_cast<unsigned long> (tv.tv_usec * 1000); +#endif + } + + std::ostream& + operator<< (std::ostream& o, time const& t) + { + return o << t.sec () << '.' + << std::setfill ('0') << std::setw (9) << t.nsec (); + } +} |