From e259c183e6069840df15ef63a1d097e08e32b71d Mon Sep 17 00:00:00 2001 From: Andrew Stitcher Date: Mon, 6 Aug 2007 23:31:17 +0000 Subject: r899@fuschia: andrew | 2007-08-07 00:30:24 +0100 Fixed Bad time calculations git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk@563335 13f79535-47bb-0310-9956-ffa450edef68 --- qpid/cpp/perftest/topic_publisher.cpp | 61 +++++++++++++++++++++-------------- 1 file changed, 37 insertions(+), 24 deletions(-) (limited to 'qpid/cpp/perftest/topic_publisher.cpp') diff --git a/qpid/cpp/perftest/topic_publisher.cpp b/qpid/cpp/perftest/topic_publisher.cpp index 96b66726c1..80815fb143 100644 --- a/qpid/cpp/perftest/topic_publisher.cpp +++ b/qpid/cpp/perftest/topic_publisher.cpp @@ -34,6 +34,7 @@ #include "qpid/sys/Time.h" #include #include +#include #include using namespace qpid::client; @@ -44,29 +45,46 @@ using std::string; bool done = 0; -class Listener : public MessageListener{ +struct timespec operator-(const struct timespec& lhs, const struct timespec& rhs) { + timespec r; + r.tv_nsec = lhs.tv_nsec - rhs.tv_nsec; + r.tv_sec = lhs.tv_sec - rhs.tv_sec; + if (r.tv_nsec < 0) { + r.tv_nsec += 1000000000; + r.tv_sec -= 1; + } + return r; +} + +std::ostream& operator<<(std::ostream& o, const struct timespec& ts) { + o << ts.tv_sec << "." << std::setw(9) << std::setfill('0') << std::right << ts.tv_nsec; + return o; +} + +double toDouble(const struct timespec& ts) { + return double(ts.tv_nsec)/1000000000 + ts.tv_sec; +} +class Listener : public MessageListener{ void set_time() { timespec ts; if (::clock_gettime(CLOCK_REALTIME, &ts)) std::cout << "Error" << std::endl; - _ts_sec = ts.tv_sec; - _ts_nsec = ts.tv_nsec; + startTime = ts; } void print_time() { timespec ts; if (::clock_gettime(CLOCK_REALTIME, &ts)) std::cout << "Error" << std::endl; - std::cout << "Total Time:" << ts.tv_sec-_ts_sec <<"." <