qps_interarrival_test.cc 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /*
  2. *
  3. * Copyright 2015 gRPC authors.
  4. *
  5. * Licensed under the Apache License, Version 2.0 (the "License");
  6. * you may not use this file except in compliance with the License.
  7. * You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. *
  17. */
  18. #include <chrono>
  19. #include <iostream>
  20. // Use the C histogram rather than C++ to avoid depending on proto
  21. #include "test/core/util/histogram.h"
  22. #include "test/core/util/test_config.h"
  23. #include "test/cpp/qps/interarrival.h"
  24. #include "test/cpp/util/test_config.h"
  25. using grpc::testing::InterarrivalTimer;
  26. using grpc::testing::RandomDistInterface;
  27. static void RunTest(RandomDistInterface&& r, int threads,
  28. const std::string& title) {
  29. InterarrivalTimer timer;
  30. timer.init(r, threads);
  31. grpc_histogram* h(grpc_histogram_create(0.01, 60e9));
  32. for (int i = 0; i < 10000000; i++) {
  33. for (int j = 0; j < threads; j++) {
  34. grpc_histogram_add(h, timer.next(j));
  35. }
  36. }
  37. std::cout << title << " Distribution" << std::endl;
  38. std::cout << "Value, Percentile" << std::endl;
  39. for (double pct = 0.0; pct < 100.0; pct += 1.0) {
  40. std::cout << grpc_histogram_percentile(h, pct) << "," << pct << std::endl;
  41. }
  42. grpc_histogram_destroy(h);
  43. }
  44. using grpc::testing::ExpDist;
  45. int main(int argc, char** argv) {
  46. grpc::testing::TestEnvironment env(argc, argv);
  47. grpc::testing::InitTest(&argc, &argv, true);
  48. RunTest(ExpDist(10.0), 5, std::string("Exponential(10)"));
  49. return 0;
  50. }