Fix definition of InterarrivalTimer to enable late initialization

and use nanoseconds
pull/1380/head
Vijay Pai 10 years ago
parent 9cf0b3b84d
commit e23aba4884
  1. 16
      test/cpp/qps/interarrival.h

@ -31,8 +31,8 @@
*
*/
#ifndef TEST_QPS_TIMER_H
#define TEST_QPS_TIMER_H
#ifndef TEST_QPS_INTERARRIVAL_H
#define TEST_QPS_INTERARRIVAL_H
#include <chrono>
#include <cmath>
@ -112,11 +112,17 @@ using qps_random_engine = std::default_random_engine;
class InterarrivalTimer {
public:
InterarrivalTimer() {}
InterarrivalTimer(const RandomDist& r, int threads, int entries=1000000) {
init(r, threads, entries);
}
void init(const RandomDist& r, int threads, int entries=1000000) {
qps_random_engine gen;
std::uniform_real_distribution<double> uniform(0.0,1.0);
for (int i=0; i<entries; i++) {
random_table_.push_back(std::chrono::microseconds(static_cast<int64_t>(1000000.0*r(uniform(gen)))));
random_table_.push_back(
std::chrono::nanoseconds(
static_cast<int64_t>(1e9*r(uniform(gen)))));
}
// Now set up the thread positions
for (int i=0; i<threads; i++) {
@ -125,14 +131,14 @@ public:
}
virtual ~InterarrivalTimer() {};
std::chrono::microseconds operator() (int thread_num) {
std::chrono::nanoseconds operator() (int thread_num) {
auto ret = *(thread_posns_[thread_num]++);
if (thread_posns_[thread_num] == random_table_.end())
thread_posns_[thread_num] = random_table_.begin();
return ret;
}
private:
typedef std::vector<std::chrono::microseconds> time_table;
typedef std::vector<std::chrono::nanoseconds> time_table;
std::vector<time_table::const_iterator> thread_posns_;
time_table random_table_;
};

Loading…
Cancel
Save