# [PATCH] change throughput display units with fast links

3 messages from 2009-10-14 to 2009-10-14. Participants: Nicolas Pitre, Johannes Sixt, Junio C Hamano.
Thread: https://gitlist.dev/t/21234

## Nicolas Pitre, 2009-10-14 03:02

Subject: [PATCH] change throughput display units with fast links
Message-ID: <alpine.LFD.2.00.0910132256280.20122@xanadu.home>
URL: https://gitlist.dev/e/alpine.LFD.2.00.0910132256280.20122%40xanadu.home

```
Switch to MiB/s when the connection is fast enough (i.e. on a LAN).

Signed-off-by: Nicolas Pitre <nico@fluxnic.net>
---
diff --git a/progress.c b/progress.c
index 132ed95..3971f49 100644
--- a/progress.c
+++ b/progress.c
@@ -131,7 +131,13 @@ static void throughput_string(struct throughput *tp, off_t total,
 	} else {
 		l -= snprintf(tp->display, l, ", %u bytes", (int)total);
 	}
-	if (rate)
+
+	if (rate > 1 << 10) {
+		int x = rate + 5;  /* for rounding */
+		snprintf(tp->display + sizeof(tp->display) - l, l,
+			 " | %u.%2.2u MiB/s",
+			 x >> 10, ((x & ((1 << 10) - 1)) * 100) >> 10);
+	} else if (rate)
 		snprintf(tp->display + sizeof(tp->display) - l, l,
 			 " | %u KiB/s", rate);
 }

```

## Johannes Sixt, 2009-10-14 07:07

Subject: Re: [PATCH] change throughput display units with fast links
Message-ID: <4AD578BD.7080201@viscovery.net>
URL: https://gitlist.dev/e/4AD578BD.7080201%40viscovery.net
In-Reply-To: <alpine.LFD.2.00.0910132256280.20122@xanadu.home>

```
Nicolas Pitre schrieb:
> +	if (rate > 1 << 10) {
> +		int x = rate + 5;  /* for rounding */
> +		snprintf(tp->display + sizeof(tp->display) - l, l,
> +			 " | %u.%2.2u MiB/s",

Shouldn't the fractional part be "%02.2u" (leading zeros instead of blanks)?

> +			 x >> 10, ((x & ((1 << 10) - 1)) * 100) >> 10);
> +	} else if (rate)
>  		snprintf(tp->display + sizeof(tp->display) - l, l,
>  			 " | %u KiB/s", rate);
>  }

-- Hannes

```

## Junio C Hamano, 2009-10-14 09:13

Subject: Re: [PATCH] change throughput display units with fast links
Message-ID: <7viqeifie3.fsf@alter.siamese.dyndns.org>
URL: https://gitlist.dev/e/7viqeifie3.fsf%40alter.siamese.dyndns.org
In-Reply-To: <4AD578BD.7080201@viscovery.net>

```
Johannes Sixt <j.sixt@viscovery.net> writes:

> Nicolas Pitre schrieb:
>> +	if (rate > 1 << 10) {
>> +		int x = rate + 5;  /* for rounding */
>> +		snprintf(tp->display + sizeof(tp->display) - l, l,
>> +			 " | %u.%2.2u MiB/s",
>
> Shouldn't the fractional part be "%02.2u" (leading zeros instead of blanks)?
>
>> +			 x >> 10, ((x & ((1 << 10) - 1)) * 100) >> 10);
>> +	} else if (rate)
>>  		snprintf(tp->display + sizeof(tp->display) - l, l,
>>  			 " | %u KiB/s", rate);
>>  }
>
> -- Hannes

Judging from the surrounding existing code, I do not think so.

    $ cat <<\EOF >j.c
    #include <stdio.h>

    int main(int ac, char **av)
    {
            printf("%u.%2.2u\n", 4, 5);
            return 0;
    }
    EOF
    $ gcc -o j j.c && ./j
    4.05

```
