benchmark.cc 776 B

123456789101112131415161718192021222324252627282930313233
  1. #include <chrono>
  2. #include <httplib.h>
  3. #include <iostream>
  4. using namespace std;
  5. struct StopWatch {
  6. StopWatch(const string &label) : label_(label) {
  7. start_ = chrono::system_clock::now();
  8. }
  9. ~StopWatch() {
  10. auto end = chrono::system_clock::now();
  11. auto diff = end - start_;
  12. auto count = chrono::duration_cast<chrono::milliseconds>(diff).count();
  13. cout << label_ << ": " << count << " millisec." << endl;
  14. }
  15. string label_;
  16. chrono::system_clock::time_point start_;
  17. };
  18. int main(void) {
  19. string body(1024 * 5, 'a');
  20. httplib::Client cli("httpbin.org", 80);
  21. for (int i = 0; i < 3; i++) {
  22. StopWatch sw(to_string(i).c_str());
  23. auto res = cli.Post("/post", body, "application/octet-stream");
  24. assert(res->status == 200);
  25. }
  26. return 0;
  27. }