diff --git a/test/cpp/qps/interarrival.h b/test/cpp/qps/interarrival.h index 9e1b688a1cf..98f4def1f2a 100644 --- a/test/cpp/qps/interarrival.h +++ b/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 #include @@ -49,7 +49,7 @@ namespace testing { // this code is required to serve as the template code for other language // stacks. Thus, this code only uses a uniform distribution of doubles [0,1) // and then provides the distribution functions itself. - + class RandomDist { public: RandomDist() {} @@ -59,7 +59,7 @@ class RandomDist { }; inline RandomDist::~RandomDist() {} - + class UniformDist GRPC_FINAL: public RandomDist { public: UniformDist(double lo, double hi): lo_(lo), range_(hi-lo) {} @@ -81,7 +81,7 @@ public: private: double lambda_recip_; }; - + class DetDist GRPC_FINAL : public RandomDist { public: explicit DetDist(double val): val_(val) {} @@ -103,20 +103,26 @@ private: double base_; double alpha_recip_; }; - + // A class library for generating pseudo-random interarrival times // in an efficient re-entrant way. The random table is built at construction // time, and each call must include the thread id of the invoker 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 uniform(0.0,1.0); for (int i=0; i(1000000.0*r(uniform(gen))))); + random_table_.push_back( + std::chrono::nanoseconds( + static_cast(1e9*r(uniform(gen))))); } // Now set up the thread positions for (int i=0; i time_table; + typedef std::vector time_table; std::vector thread_posns_; time_table random_table_; }; diff --git a/test/cpp/qps/qps_interarrival_test.cc b/test/cpp/qps/qps_interarrival_test.cc index e5af9989214..14af4c65067 100644 --- a/test/cpp/qps/qps_interarrival_test.cc +++ b/test/cpp/qps/qps_interarrival_test.cc @@ -69,9 +69,9 @@ int main(int argc, char **argv) { RunTest(InterarrivalTimer(ExpDist(10.0), 5), std::string("Exponential(10)")); RunTest(InterarrivalTimer(DetDist(5.0), 5), std::string("Det(5)")); RunTest(InterarrivalTimer(UniformDist(0.0,10.0), 5), - std::string("Uniform(1,10)")); + std::string("Uniform(1,10)")); RunTest(InterarrivalTimer(ParetoDist(1.0,1.0), 5), - std::string("Pareto(1,1)")); - + std::string("Pareto(1,1)")); + return 0; }