
On Mon, May 10, 2010 at 4:51 AM, Nick Thompson nick.thompson@ge.com wrote:
Modification of print_size to avoid use of divides and especially long long divides. Keep the binary scale factor in terms of bit shifts instead. This should be faster, since the previous code gave the compiler no clues that the divides where always powers of two, preventing optimisation.
Signed-off-by: Nick Thompson nick.thompson@ge.com
This code almost works. It seems to have trouble printing fractional values. Using this loop:
unsigned int i;
for (i = 0; i < 63; i++) print_size(3ULL << i, "\n");
I get this output. Notice that it rounds 1.5 to 2 on sizes less than a terabyte.
3 Bytes 6 Bytes 12 Bytes 24 Bytes 48 Bytes 96 Bytes 192 Bytes 384 Bytes 768 Bytes 2 KiB 3 KiB 6 KiB 12 KiB 24 KiB 48 KiB 96 KiB 192 KiB 384 KiB 768 KiB 2 MiB 3 MiB 6 MiB 12 MiB 24 MiB 48 MiB 96 MiB 192 MiB 384 MiB 768 MiB 2 GiB 3 GiB 6 GiB 12 GiB 24 GiB 48 GiB 96 GiB 192 GiB 384 GiB 768 GiB 1.5 TiB 3 TiB 6 TiB 12 TiB 24 TiB 48 TiB 96 TiB 192 TiB 384 TiB 768 TiB 1.5 PiB 3 PiB 6 PiB 12 PiB 24 PiB 48 PiB 96 PiB 192 PiB 384 PiB 768 PiB 1.5 EiB 3 EiB 6 EiB 12 EiB