Created
June 14, 2014 18:07
-
-
Save erikerlandson/b55f62bdaca5d9eb41de to your computer and use it in GitHub Desktop.
Demonstrate basic boost date/time usage of clock, duration and time comparison. Compare cost of local_time() and universal_time(). The universal_time() function is about 2x faster.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include "boost/date_time/posix_time/posix_time_types.hpp" | |
using namespace boost::posix_time; | |
int main(int argc, char** argv) { | |
const int dsec = 5; | |
{ | |
ptime t0 = microsec_clock::local_time(); | |
ptime tt = t0 + seconds(dsec); | |
long n = 0; | |
while (true) { | |
++n; | |
if (microsec_clock::local_time() > tt) break; | |
} | |
std::cout << "local_time(): n= " << n << " rate= " << double(n)/double(dsec) << std::endl; | |
} | |
{ | |
ptime t0 = microsec_clock::universal_time(); | |
ptime tt = t0 + seconds(dsec); | |
long n = 0; | |
while (true) { | |
++n; | |
if (microsec_clock::universal_time() > tt) break; | |
} | |
std::cout << "universal_time(): n= " << n << " rate= " << double(n)/double(dsec) << std::endl; | |
} | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ ./boost_date_time | |
local_time(): n= 7566784 rate= 1.51336e+06 | |
universal_time(): n= 14736859 rate= 2.94737e+06 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment