I want to send 99999999 get requests and print the status code fast I wrote this struct to handle each request:
struct node{
std::string api;
bool done;
node() = default;
node(std::string const &a) : api(a) ,
done(false){}
void work(){
std::thread([&]{
auto f = cpr::GetAsync(cpr::Url{api.c_str()}, cpr::Header{"headers"}, cpr::Cookies{"cookies"});
std::cout<<f.status_code<<'\n';
done=true;
}).detach();
}
};
Then I created this array node n[215];
, a loop will create the urls used in requests:
//build url string
for(int i=0; i<215; ++i){
//another code build the api here after that i make the object with the url
node x(api);
n[i]=std::move(x);
}
after that i call this function to start each request:
void init(node*x){
for(unsigned i=0; i<256;++i){
x[i].work();
}
}
// in main
std::thread th(init, n);
th.join();
when i done with the array node n[215] i do the same thing with the n store 215 object and the work() function for each object until 99999999 but it takes a lot of time, how to done with 999999999 fast, Any suggestions please, thanks