Skip to content

Instantly share code, notes, and snippets.

@jglenn9k
Last active July 5, 2018 20:49

Revisions

  1. jglenn9k revised this gist Mar 30, 2018. 1 changed file with 5 additions and 2 deletions.
    7 changes: 5 additions & 2 deletions check_page_speed.cpp
    Original file line number Diff line number Diff line change
    @@ -3,6 +3,9 @@
    #include <cstdio>
    #include <curl/curl.h>

    // James Glenn <thedonkdonk@gmail.com>
    // 2018-03-30

    static size_t WriteCallback(void *contents, size_t size, size_t nmemb, void *userp) {
    ((std::string*)userp)->append((char*)contents, size * nmemb);
    return size * nmemb;
    @@ -56,8 +59,8 @@ int main(int argc, char **argv) {

    if((CURLE_OK == res) && response_code) {
    printf("Redirected to: %s\n", url);
    printf("Response Code: %d\n", response_code);
    printf("Total Redirects: %d\n", redirects);
    printf("Response Code: %ld\n", response_code);
    printf("Total Redirects: %ld\n", redirects);
    printf("Downloaded: %.0f bytes\n", dlsize);
    printf("Download speed %.0f bytes/sec\n", dlspeed);

  2. jglenn9k revised this gist Mar 29, 2018. 1 changed file with 60 additions and 60 deletions.
    120 changes: 60 additions & 60 deletions check_page_speed.cpp
    Original file line number Diff line number Diff line change
    @@ -4,74 +4,74 @@
    #include <curl/curl.h>

    static size_t WriteCallback(void *contents, size_t size, size_t nmemb, void *userp) {
    ((std::string*)userp)->append((char*)contents, size * nmemb);
    return size * nmemb;
    ((std::string*)userp)->append((char*)contents, size * nmemb);
    return size * nmemb;
    }

    int main(int argc, char **argv) {
    if (argc != 2) {
    std::cout << "ERROR - Must provide a URL." << std::endl;
    return 2;
    }
    CURL *curl;
    CURLcode res;
    std::string readBuffer;
    if (argc != 2) {
    std::cout << "ERROR - Must provide a URL." << std::endl;
    return 2;
    }
    CURL *curl;
    CURLcode res;
    std::string readBuffer;

    curl = curl_easy_init();
    if(curl) {
    curl = curl_easy_init();
    if(curl) {

    curl_easy_setopt(curl, CURLOPT_HEADER, false);
    curl_easy_setopt(curl, CURLOPT_ENCODING, "gzip");
    curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
    curl_easy_setopt(curl, CURLOPT_VERBOSE, false);
    curl_easy_setopt(curl, CURLOPT_USERAGENT, "Page Speed Checker v1.0");
    curl_easy_setopt(curl, CURLOPT_URL, argv[1]);
    curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, WriteCallback);
    curl_easy_setopt(curl, CURLOPT_WRITEDATA, &readBuffer);
    res = curl_easy_perform(curl);
    curl_easy_setopt(curl, CURLOPT_HEADER, false);
    curl_easy_setopt(curl, CURLOPT_ENCODING, "gzip");
    curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
    curl_easy_setopt(curl, CURLOPT_VERBOSE, false);
    curl_easy_setopt(curl, CURLOPT_USERAGENT, "Page Speed Checker v1.0");
    curl_easy_setopt(curl, CURLOPT_URL, argv[1]);
    curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, WriteCallback);
    curl_easy_setopt(curl, CURLOPT_WRITEDATA, &readBuffer);
    res = curl_easy_perform(curl);
    if(CURLE_OK == res) {
    char *url = NULL;
    curl_easy_getinfo(curl, CURLINFO_EFFECTIVE_URL, &url);
    long response_code;
    curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &response_code);
    double dlsize;
    curl_easy_getinfo(curl, CURLINFO_SIZE_DOWNLOAD, &dlsize);
    double dlspeed;
    curl_easy_getinfo(curl, CURLINFO_SPEED_DOWNLOAD, &dlspeed);
    double namelookup;
    curl_easy_getinfo(curl, CURLINFO_NAMELOOKUP_TIME, &namelookup);
    double connect;
    curl_easy_getinfo(curl, CURLINFO_CONNECT_TIME, &connect);
    double pretransfer;
    curl_easy_getinfo(curl, CURLINFO_PRETRANSFER_TIME, &pretransfer);
    double start;
    curl_easy_getinfo(curl, CURLINFO_STARTTRANSFER_TIME, &start);
    double redirect;
    curl_easy_getinfo(curl, CURLINFO_REDIRECT_TIME, &redirect);
    double total;
    curl_easy_getinfo(curl, CURLINFO_TOTAL_TIME, &total);
    long redirects;
    curl_easy_getinfo(curl, CURLINFO_REDIRECT_COUNT, &redirects);
    char *url = NULL;
    curl_easy_getinfo(curl, CURLINFO_EFFECTIVE_URL, &url);
    long response_code;
    curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &response_code);
    double dlsize;
    curl_easy_getinfo(curl, CURLINFO_SIZE_DOWNLOAD, &dlsize);
    double dlspeed;
    curl_easy_getinfo(curl, CURLINFO_SPEED_DOWNLOAD, &dlspeed);
    double namelookup;
    curl_easy_getinfo(curl, CURLINFO_NAMELOOKUP_TIME, &namelookup);
    double connect;
    curl_easy_getinfo(curl, CURLINFO_CONNECT_TIME, &connect);
    double pretransfer;
    curl_easy_getinfo(curl, CURLINFO_PRETRANSFER_TIME, &pretransfer);
    double start;
    curl_easy_getinfo(curl, CURLINFO_STARTTRANSFER_TIME, &start);
    double redirect;
    curl_easy_getinfo(curl, CURLINFO_REDIRECT_TIME, &redirect);
    double total;
    curl_easy_getinfo(curl, CURLINFO_TOTAL_TIME, &total);
    long redirects;
    curl_easy_getinfo(curl, CURLINFO_REDIRECT_COUNT, &redirects);


    if((CURLE_OK == res) && response_code) {
    printf("Redirected to: %s\n", url);
    printf("Response Code: %d\n", response_code);
    printf("Total Redirects: %d\n", redirects);
    printf("Downloaded: %.0f bytes\n", dlsize);
    printf("Download speed %.0f bytes/sec\n", dlspeed);

    printf("Name Lookup Time: %.2f\n", namelookup);
    printf("Connect Time: %.2f\n", connect);
    printf("Pretransfer Time: %.2f\n", pretransfer);
    printf("Start Time: %.2f\n", start);
    printf("Redirect Time: %.2f\n", redirect);
    printf("Total Time: %.2f\n", total);
    if((CURLE_OK == res) && response_code) {
    printf("Redirected to: %s\n", url);
    printf("Response Code: %d\n", response_code);
    printf("Total Redirects: %d\n", redirects);
    printf("Downloaded: %.0f bytes\n", dlsize);
    printf("Download speed %.0f bytes/sec\n", dlspeed);

    }
    }
    curl_easy_cleanup(curl);
    printf("Name Lookup Time: %.2f\n", namelookup);
    printf("Connect Time: %.2f\n", connect);
    printf("Pretransfer Time: %.2f\n", pretransfer);
    printf("Start Time: %.2f\n", start);
    printf("Redirect Time: %.2f\n", redirect);
    printf("Total Time: %.2f\n", total);

    }
    return 0;
    }
    }
    curl_easy_cleanup(curl);

    }
    return 0;
    }
  3. jglenn9k revised this gist Mar 29, 2018. No changes.
  4. jglenn9k created this gist Mar 29, 2018.
    77 changes: 77 additions & 0 deletions check_page_speed.cpp
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,77 @@
    #include <iostream>
    #include <string>
    #include <cstdio>
    #include <curl/curl.h>

    static size_t WriteCallback(void *contents, size_t size, size_t nmemb, void *userp) {
    ((std::string*)userp)->append((char*)contents, size * nmemb);
    return size * nmemb;
    }

    int main(int argc, char **argv) {
    if (argc != 2) {
    std::cout << "ERROR - Must provide a URL." << std::endl;
    return 2;
    }
    CURL *curl;
    CURLcode res;
    std::string readBuffer;

    curl = curl_easy_init();
    if(curl) {

    curl_easy_setopt(curl, CURLOPT_HEADER, false);
    curl_easy_setopt(curl, CURLOPT_ENCODING, "gzip");
    curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
    curl_easy_setopt(curl, CURLOPT_VERBOSE, false);
    curl_easy_setopt(curl, CURLOPT_USERAGENT, "Page Speed Checker v1.0");
    curl_easy_setopt(curl, CURLOPT_URL, argv[1]);
    curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, WriteCallback);
    curl_easy_setopt(curl, CURLOPT_WRITEDATA, &readBuffer);
    res = curl_easy_perform(curl);
    if(CURLE_OK == res) {
    char *url = NULL;
    curl_easy_getinfo(curl, CURLINFO_EFFECTIVE_URL, &url);
    long response_code;
    curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &response_code);
    double dlsize;
    curl_easy_getinfo(curl, CURLINFO_SIZE_DOWNLOAD, &dlsize);
    double dlspeed;
    curl_easy_getinfo(curl, CURLINFO_SPEED_DOWNLOAD, &dlspeed);
    double namelookup;
    curl_easy_getinfo(curl, CURLINFO_NAMELOOKUP_TIME, &namelookup);
    double connect;
    curl_easy_getinfo(curl, CURLINFO_CONNECT_TIME, &connect);
    double pretransfer;
    curl_easy_getinfo(curl, CURLINFO_PRETRANSFER_TIME, &pretransfer);
    double start;
    curl_easy_getinfo(curl, CURLINFO_STARTTRANSFER_TIME, &start);
    double redirect;
    curl_easy_getinfo(curl, CURLINFO_REDIRECT_TIME, &redirect);
    double total;
    curl_easy_getinfo(curl, CURLINFO_TOTAL_TIME, &total);
    long redirects;
    curl_easy_getinfo(curl, CURLINFO_REDIRECT_COUNT, &redirects);


    if((CURLE_OK == res) && response_code) {
    printf("Redirected to: %s\n", url);
    printf("Response Code: %d\n", response_code);
    printf("Total Redirects: %d\n", redirects);
    printf("Downloaded: %.0f bytes\n", dlsize);
    printf("Download speed %.0f bytes/sec\n", dlspeed);

    printf("Name Lookup Time: %.2f\n", namelookup);
    printf("Connect Time: %.2f\n", connect);
    printf("Pretransfer Time: %.2f\n", pretransfer);
    printf("Start Time: %.2f\n", start);
    printf("Redirect Time: %.2f\n", redirect);
    printf("Total Time: %.2f\n", total);

    }
    }
    curl_easy_cleanup(curl);

    }
    return 0;
    }