summaryrefslogtreecommitdiff
path: root/cpp
diff options
context:
space:
mode:
authorAndrew Stitcher <astitcher@apache.org>2007-08-06 23:31:17 +0000
committerAndrew Stitcher <astitcher@apache.org>2007-08-06 23:31:17 +0000
commitcd31479023158c05208bfe4c4084bd59521123dd (patch)
treeb7d9c060c5981f6926193e94fee316f400ea197d /cpp
parentdebb32550a5bc94c673397809443965611d38283 (diff)
downloadqpid-python-cd31479023158c05208bfe4c4084bd59521123dd.tar.gz
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/qpid@563335 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'cpp')
-rw-r--r--cpp/perftest/topic_publisher.cpp61
1 files changed, 37 insertions, 24 deletions
diff --git a/cpp/perftest/topic_publisher.cpp b/cpp/perftest/topic_publisher.cpp
index 96b66726c1..80815fb143 100644
--- a/cpp/perftest/topic_publisher.cpp
+++ b/cpp/perftest/topic_publisher.cpp
@@ -34,6 +34,7 @@
#include "qpid/sys/Time.h"
#include <cstdlib>
#include <iostream>
+#include <iomanip>
#include <time.h>
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 <<"." <<ts.tv_nsec - _ts_nsec << std::endl;
- float rate = messageCount*2/(ts.tv_sec-_ts_sec);
+ std::cout << "Total Time:" << ts-startTime << std::endl;
+ double rate = messageCount*2/toDouble(ts-startTime);
std::cout << "returned Messages:" << messageCount << std::endl;
std::cout << "round trip Rate:" << rate << std::endl;
}
- time_t _ts_sec; ///< Timestamp of journal initilailization
- u_int32_t _ts_nsec; ///< Timestamp of journal initilailization
+ struct timespec startTime;
int messageCount;
public:
@@ -131,27 +149,22 @@ int main() {
- time_t _ts_sec; ///< Timestamp of journal initilailization
- u_int32_t _ts_nsec; ///< Timestamp of journal initilailization
- timespec ts;
- if (::clock_gettime(CLOCK_REALTIME, &ts))
- std::cout << "Error" << std::endl;
- _ts_sec = ts.tv_sec;
- _ts_nsec = ts.tv_nsec;
-
+ struct timespec startTime;
+ if (::clock_gettime(CLOCK_REALTIME, &startTime))
+ std::cout << "Error" << std::endl;
-
for (int i=0; i<count; i++) {
- msg.setData("Message 0123456789 ");
- channel.publish(msg, Exchange::STANDARD_TOPIC_EXCHANGE, queueName);
+ msg.setData("Message 0123456789 ");
+ channel.publish(msg, Exchange::STANDARD_TOPIC_EXCHANGE, queueName);
}
- if (::clock_gettime(CLOCK_REALTIME, &ts))
- std::cout << "Error" << std::endl;
- std::cout << "publish Time:" << ts.tv_sec-_ts_sec <<"." <<ts.tv_nsec - _ts_nsec << std::endl;
- float rate = count/(ts.tv_sec-_ts_sec);
- std::cout << "publish Messages:" << count << std::endl;
- std::cout << "publish Rate:" << rate << std::endl;
+ struct timespec endTime;
+ if (::clock_gettime(CLOCK_REALTIME, &endTime))
+ std::cout << "Error" << std::endl;
+ std::cout << "publish Time:" << endTime-startTime << std::endl;
+ double rate = count/toDouble(endTime-startTime);
+ std::cout << "publish Messages:" << count << std::endl;
+ std::cout << "publish Rate:" << rate << std::endl;
msg.setData(queueName); // last message to queue.