cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: header bytes not being reset on each perform

From: Rick Jones <raj_at_cup.hp.com>
Date: Wed, 24 Jan 2001 16:05:50 -0800

so, now that I have the questionof header bytes answered, there also
appears to be a problem (perhaps mine, but i'm not sure) with the total
time reported by getinfo. i've modified the test program to do all the
cleanup and init, and stuck it into a loop. i retrieve the same 16MB
file across a Gigabit link ten times in a row. i display the libcurl's
thoughts as to the download bytes, time and speed, as well as my own
measure of the total time (real_time) and get this

$./curl_test2
dnld_size 16777216 dnld_time 0.161800 real_time 0.234660 dnld_speed
70959511.74
dnld_size 16777216 dnld_time 0.001345 real_time 0.232628 dnld_speed
943494.42
dnld_size 16777216 dnld_time 0.001078 real_time 0.232403 dnld_speed
3885899.81
dnld_size 16777216 dnld_time 0.001066 real_time 0.232534 dnld_speed
3929643.53
dnld_size 16777216 dnld_time 0.228603 real_time 0.232159 dnld_speed
72270132.06
dnld_size 16777216 dnld_time 0.001023 real_time 0.237941 dnld_speed
4094819.16
dnld_size 16777216 dnld_time 0.001268 real_time 0.232072 dnld_speed
3303627.76
dnld_size 16777216 dnld_time 0.001019 real_time 0.232453 dnld_speed
4110893.03
dnld_size 16777216 dnld_time 0.001028 real_time 0.232858 dnld_speed
4074902.72
dnld_size 16777216 dnld_time 0.060077 real_time 0.233693 dnld_speed
68626079.86

seems there is a big difference in the total time reported by libcurl
(and hence the download speed) and the time I measure directly with
gettimeofday() calls bracketing the curl_easy_perform() call. when
retrieving an http URL, the "transaction" is the entire download yes?
the implication is that it would be given that download size is listed
as 16MB instead of some intermediate length.

rick jones

-- 
ftp://ftp.cup.hp.com/dist/networking/misc/rachel/
these opinions are mine, all mine; HP might not want them anyway... :)
feel free to email, OR post, but please do NOT do BOTH...
my email address is raj in the cup.hp.com domain...

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

#include <curl/curl.h>
#include <curl/types.h>
#include <curl/easy.h>

unsigned long total_bytes = 0;
double total_time = 0.0;
double connect_time = 0.0;
double download_size = 0.0;
unsigned long header_bytes = 0L;
unsigned long request_size = 0L;
double download_speed = 0.0;

size_t write_data(void *ptr, size_t size, size_t nmemb, FILE *stream)
{
  /* printf("pretended to write %d bytes\n",size*nmemb); */
  total_bytes += (size * nmemb);
  return size*nmemb;
}

int main(int argc, char **argv)
{
  CURL *curl_handle;
  char *headerfilename = "head.out";
  FILE *headerfile;
  char *bodyfilename = "body.out";
  FILE *bodyfile;
  int i;

  struct timeval time1,time2;
  double elapsed_time;
  int sec,usec;

  for (i=0;i<10;i++) {
   /* init the curl session */
   curl_handle = curl_easy_init();
 
   /* set URL to get */
   curl_easy_setopt(curl_handle, CURLOPT_URL, "http://ftpsut/foo");
 
   /* no progress meter please */
   curl_easy_setopt(curl_handle, CURLOPT_NOPROGRESS, 1);
 
   /* shut up completely */
   curl_easy_setopt(curl_handle, CURLOPT_MUTE, 1);
 
   /* send all data to this function */
   curl_easy_setopt(curl_handle, CURLOPT_WRITEFUNCTION, write_data);
 
   /* open the files */
   headerfile = fopen(headerfilename,"w");
   if (headerfile == NULL) {
     curl_easy_cleanup(curl_handle);
     return -1;
   }
   bodyfile = fopen(bodyfilename,"w");
   if (bodyfile == NULL) {
     curl_easy_cleanup(curl_handle);
     return -1;
   }
   
   /* we want the headers to this file handle */
   curl_easy_setopt(curl_handle, CURLOPT_WRITEHEADER, headerfile);
   
   /* pass the actually download file to this file handle */
   curl_easy_setopt(curl_handle, CURLOPT_FILE, bodyfile);
   
   gettimeofday(&time1,NULL);
   /* get it! */
   curl_easy_perform(curl_handle);
   gettimeofday(&time2,NULL);

   /* retrieve some stats */
   
   curl_easy_getinfo(curl_handle, CURLINFO_TOTAL_TIME, &total_time);
   curl_easy_getinfo(curl_handle, CURLINFO_CONNECT_TIME, &connect_time);
   curl_easy_getinfo(curl_handle, CURLINFO_HEADER_SIZE, &header_bytes);
   curl_easy_getinfo(curl_handle, CURLINFO_SIZE_DOWNLOAD, &download_size);
   curl_easy_getinfo(curl_handle, CURLINFO_SPEED_DOWNLOAD, &download_speed);
   curl_easy_getinfo(curl_handle, CURLINFO_REQUEST_SIZE, &request_size);

   if (time2.tv_usec < time1.tv_usec) {
     time2.tv_usec += 1000000;
     time2.tv_sec -= 1;
   }
   
   sec = time2.tv_sec - time1.tv_sec;
   usec = time2.tv_usec - time1.tv_usec;
   elapsed_time = (float)sec + ((float)usec/(float)1000000.0);
   
   printf("dnld_size %.0f dnld_time %f real_time %f dnld_speed %.2f\n",
          download_size,total_time,elapsed_time,download_speed);
   
   curl_easy_cleanup(curl_handle);
   
  }

  /* close the header file */
  fclose(headerfile);

  return 0;
}

_______________________________________________
Curl-library mailing list
Curl-library_at_lists.sourceforge.net
http://lists.sourceforge.net/lists/listinfo/curl-library
Received on 2001-01-25