Last active
March 10, 2016 17:33
-
-
Save bobjansen/3fa8d539a44eb6b39e41 to your computer and use it in GitHub Desktop.
cpr Sessions, better response
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This is based on the example cpr project | |
/* | |
* My output was: | |
➜ build git:(master) ✗ ./example | |
elapsed time: 0.533153s | |
elapsed time: 0.537888s | |
elapsed time: 0.502068s | |
elapsed time: 0.122032s | |
elapsed time: 0.125355s | |
*/ | |
#include <chrono> | |
#include <cpr/cpr.h> | |
#include <iostream> | |
void request() | |
{ | |
auto start = std::chrono::system_clock::now(); | |
auto response = cpr::Get(cpr::Url{"https://httpbin.org/get"}); | |
auto end = std::chrono::system_clock::now(); | |
printDuration(start, end); | |
//std::cout << response.text << std::endl; | |
} | |
void request2(cpr::Session& session) | |
{ | |
auto start = std::chrono::system_clock::now(); | |
auto response = session.Get(); | |
auto end = std::chrono::system_clock::now(); | |
printDuration(start, end); | |
//std::cout << response.text << std::endl; | |
} | |
int main(int argc, char** argv) { | |
// Without session mgmt. | |
request(); | |
request(); | |
cpr::Session session; | |
auto url = cpr::Url{"https://httpbin.org/get"}; | |
session.SetUrl(url); | |
request2(session); | |
request2(session); | |
request2(session); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment