What units does curl use for bandwidth?

17

4

curl on the command-line displays progress like this:

  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  8 1000M    8 85.2M    0     0    57k      0  1:06:13  0:05:38  1:00:35   47k

The speed displayed in this example is 47k. But what does this mean? Is this:

  • 47kiB, that is 47 * 1024 bytes
  • 47kB, that is, 47 * 1000 bytes
  • 47kb, that is, 47 * 1000 bits (bits are often used to measure speed)

And is it:

  • per second
  • or per minute?

Flimm

Posted 2015-08-05T10:57:55.683

Reputation: 6 317

1

Similar question for wget: http://superuser.com/q/184331/90668

– Flimm – 2015-08-05T10:58:30.813

possible duplicate of How accurate is CURL's 'current rate' in the progress meter?

– DavidPostill – 2015-08-05T12:38:01.437

Answers

14

What units does curl use for bandwidth?

According to the source code it is kiB per second.


Here you can see the definition uses 1024 and not 1000

/* The point of this function would be to return a string of the input data,
   but never longer than 5 columns (+ one zero byte).
   Add suffix k, M, G when suitable... */
static char *max5data(curl_off_t bytes, char *max5)
{
#define ONE_KILOBYTE  CURL_OFF_T_C(1024)
#define ONE_MEGABYTE (CURL_OFF_T_C(1024) * ONE_KILOBYTE)
#define ONE_GIGABYTE (CURL_OFF_T_C(1024) * ONE_MEGABYTE)
#define ONE_TERABYTE (CURL_OFF_T_C(1024) * ONE_GIGABYTE)
#define ONE_PETABYTE (CURL_OFF_T_C(1024) * ONE_TERABYTE)

...

}

Here you can see the calculation is done in ms and then divided by 1000 to get seconds.

  /* Calculate the average speed the last 'span_ms' milliseconds */
  {
    curl_off_t amount = data->progress.speeder[nowindex]-
      data->progress.speeder[checkindex];

    if(amount > CURL_OFF_T_C(4294967) /* 0xffffffff/1000 */)
      /* the 'amount' value is bigger than would fit in 32 bits if
         multiplied with 1000, so we use the double math for this */
      data->progress.current_speed = (curl_off_t)
        ((double)amount/((double)span_ms/1000.0));
    else
      /* the 'amount' value is small enough to fit within 32 bits even
         when multiplied with 1000 */
      data->progress.current_speed = amount*CURL_OFF_T_C(1000)/span_ms;
  }

DavidPostill

Posted 2015-08-05T10:57:55.683

Reputation: 118 938

1

I had to look this up, so hopefully this saves someone the effort: kiB is a kibibyte and you can search sites like this one to convert it to other units.

– SteveLambert – 2017-04-18T19:25:42.760