Skip to content

Instantly share code, notes, and snippets.

@ylmrx
Last active March 22, 2019 11:30
Show Gist options
  • Save ylmrx/afcce1cf3e979d6abfbd068b084bcda9 to your computer and use it in GitHub Desktop.
Save ylmrx/afcce1cf3e979d6abfbd068b084bcda9 to your computer and use it in GitHub Desktop.
multithreaded fast C code to benchmark stuffs fast
#include <curl/curl.h>
#include <omp.h>
#define MAX_THREAD 32
#define LASERS 100
#define URL "http://www.example.com"
int main(int argc, char *argv[]) {
int tid, i = 0;
FILE *devnull;
devnull = fopen("/dev/null", "w");
#pragma omp parallel private(i) num_threads(MAX_THREAD)
{
#pragma omp for
for(i = 0; i < LASERS; ++i) {
tid = omp_get_thread_num();
CURLcode ret;
CURL *hnd;
double total;
curl_off_t dl, rate;
hnd = curl_easy_init();
curl_easy_setopt(hnd, CURLOPT_URL, URL);
curl_easy_setopt(hnd, CURLOPT_NOPROGRESS, 1L);
curl_easy_setopt(hnd, CURLOPT_WRITEDATA, devnull);
ret = curl_easy_perform(hnd);
if(ret == CURLE_OK) {
curl_easy_getinfo(hnd, CURLINFO_TOTAL_TIME, &total);
curl_easy_getinfo(hnd, CURLINFO_SIZE_DOWNLOAD_T, &dl);
curl_easy_getinfo(hnd, CURLINFO_SPEED_DOWNLOAD_T, &rate);
printf("thread = %d, task = %d --- time : %.7f --- size=%" CURL_FORMAT_CURL_OFF_T
", rate=%" CURL_FORMAT_CURL_OFF_T "b/s\n", tid, i, total, dl, rate);
}
curl_easy_cleanup(hnd);
hnd = NULL;
}
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment