I noticed od was very slow and traced it to it using xprintf:
$ timeout 2 od-xprintf -Ax -tx1z -v /dev/zero | pv >/dev/null
3.66MB 0:00:02 [1.86MB/s]
$ timeout 2 od-printf -Ax -tx1z -v /dev/zero | pv >/dev/null
19.6MB 0:00:02 [9.96MB/s]
The reason is because xprintf pulls in the whole gnulib vasnprintf
implementation, and then it does a huge number of reallocs.
So there are two possible issues; a redundant and slow replacement.
The reason my vprintf from glibc-2.12.90-21.i686 is not used is because:
$ grep gl_cv_func_printf.*no$ config.log
gl_cv_func_printf_infinite_long_double=no
I had a quick look at that check, and my suspicions are raised
as it was added in 2007. Is my glibc still not up to spec?
I extracted the test (attached) which output:
[0.000000e+4922] is not NAN
[0e+4922] is not NAN
[0.000000] is not NAN
[0.000000e+00] is not NAN
[0] is not NAN
[1.550000] is not NAN
[1.550000e+00] is not NAN
[1.55] is not NAN
[0.000000] is not NAN
[8.405258e-4934] is not NAN
[8.40526e-4934] is not NAN
cheers,
Pádraig.
#include <float.h>
#include <stdio.h>
#include <string.h>
#define CHECK_PRINTF_SAFE 1
static int
strisnan (const char *string, size_t start_index, size_t end_index)
{
if (start_index < end_index)
{
if (string[start_index] == '-')
start_index++;
if (start_index + 3 <= end_index
&& memcmp (string + start_index, "nan", 3) == 0)
{
start_index += 3;
if (start_index == end_index
|| (string[start_index] == '(' && string[end_index - 1] == ')'))
return 1;
}
}
printf ("[%.*s] is not NAN\n", end_index - start_index, string + start_index);
return 0;
}
static char buf[10000];
static long double zeroL = 0.0L;
int main ()
{
int result = 0;
if (sprintf (buf, "%Lf", 1.0L / 0.0L) < 0
|| (strcmp (buf, "inf") != 0 && strcmp (buf, "infinity") != 0))
result |= 1;
if (sprintf (buf, "%Lf", -1.0L / 0.0L) < 0
|| (strcmp (buf, "-inf") != 0 && strcmp (buf, "-infinity") != 0))
result |= 1;
if (sprintf (buf, "%Lf", zeroL / zeroL) < 0
|| !strisnan (buf, 0, strlen (buf)))
result |= 1;
if (sprintf (buf, "%Le", 1.0L / 0.0L) < 0
|| (strcmp (buf, "inf") != 0 && strcmp (buf, "infinity") != 0))
result |= 1;
if (sprintf (buf, "%Le", -1.0L / 0.0L) < 0
|| (strcmp (buf, "-inf") != 0 && strcmp (buf, "-infinity") != 0))
result |= 1;
if (sprintf (buf, "%Le", zeroL / zeroL) < 0
|| !strisnan (buf, 0, strlen (buf)))
result |= 1;
if (sprintf (buf, "%Lg", 1.0L / 0.0L) < 0
|| (strcmp (buf, "inf") != 0 && strcmp (buf, "infinity") != 0))
result |= 1;
if (sprintf (buf, "%Lg", -1.0L / 0.0L) < 0
|| (strcmp (buf, "-inf") != 0 && strcmp (buf, "-infinity") != 0))
result |= 1;
if (sprintf (buf, "%Lg", zeroL / zeroL) < 0
|| !strisnan (buf, 0, strlen (buf)))
result |= 1;
#if CHECK_PRINTF_SAFE && ((defined __ia64 && LDBL_MANT_DIG == 64) || (defined __x86_64__ || defined __amd64__) || (defined __i386 || defined __i386__ || defined _I386 || defined _M_IX86 || defined _X86_))
/* Representation of an 80-bit 'long double' as an initializer for a sequence
of 'unsigned int' words. */
# ifdef WORDS_BIGENDIAN
# define LDBL80_WORDS(exponent,manthi,mantlo) \
{ ((unsigned int) (exponent) << 16) | ((unsigned int) (manthi) >> 16), \
((unsigned int) (manthi) << 16) | (unsigned int) (mantlo) >> 16), \
(unsigned int) (mantlo) << 16 \
}
# else
# define LDBL80_WORDS(exponent,manthi,mantlo) \
{ mantlo, manthi, exponent }
# endif
{ /* Quiet NaN. */
static union { unsigned int word[4]; long double value; } x =
{ LDBL80_WORDS (0xFFFF, 0xC3333333, 0x00000000) };
if (sprintf (buf, "%Lf", x.value) < 0
|| !strisnan (buf, 0, strlen (buf)))
result |= 2;
if (sprintf (buf, "%Le", x.value) < 0
|| !strisnan (buf, 0, strlen (buf)))
result |= 2;
if (sprintf (buf, "%Lg", x.value) < 0
|| !strisnan (buf, 0, strlen (buf)))
result |= 2;
}
{
/* Signalling NaN. */
static union { unsigned int word[4]; long double value; } x =
{ LDBL80_WORDS (0xFFFF, 0x83333333, 0x00000000) };
if (sprintf (buf, "%Lf", x.value) < 0
|| !strisnan (buf, 0, strlen (buf)))
result |= 2;
if (sprintf (buf, "%Le", x.value) < 0
|| !strisnan (buf, 0, strlen (buf)))
result |= 2;
if (sprintf (buf, "%Lg", x.value) < 0
|| !strisnan (buf, 0, strlen (buf)))
result |= 2;
}
{ /* Pseudo-NaN. */
static union { unsigned int word[4]; long double value; } x =
{ LDBL80_WORDS (0xFFFF, 0x40000001, 0x00000000) };
if (sprintf (buf, "%Lf", x.value) < 0
|| !strisnan (buf, 0, strlen (buf)))
result |= 4;
if (sprintf (buf, "%Le", x.value) < 0
|| !strisnan (buf, 0, strlen (buf)))
result |= 4;
if (sprintf (buf, "%Lg", x.value) < 0
|| !strisnan (buf, 0, strlen (buf)))
result |= 4;
}
{ /* Pseudo-Infinity. */
static union { unsigned int word[4]; long double value; } x =
{ LDBL80_WORDS (0xFFFF, 0x00000000, 0x00000000) };
if (sprintf (buf, "%Lf", x.value) < 0
|| !strisnan (buf, 0, strlen (buf)))
result |= 8;
if (sprintf (buf, "%Le", x.value) < 0
|| !strisnan (buf, 0, strlen (buf)))
result |= 8;
if (sprintf (buf, "%Lg", x.value) < 0
|| !strisnan (buf, 0, strlen (buf)))
result |= 8;
}
{ /* Pseudo-Zero. */
static union { unsigned int word[4]; long double value; } x =
{ LDBL80_WORDS (0x4004, 0x00000000, 0x00000000) };
if (sprintf (buf, "%Lf", x.value) < 0
|| !strisnan (buf, 0, strlen (buf)))
result |= 16;
if (sprintf (buf, "%Le", x.value) < 0
|| !strisnan (buf, 0, strlen (buf)))
result |= 16;
if (sprintf (buf, "%Lg", x.value) < 0
|| !strisnan (buf, 0, strlen (buf)))
result |= 16;
}
{ /* Unnormalized number. */
static union { unsigned int word[4]; long double value; } x =
{ LDBL80_WORDS (0x4000, 0x63333333, 0x00000000) };
if (sprintf (buf, "%Lf", x.value) < 0
|| !strisnan (buf, 0, strlen (buf)))
result |= 32;
if (sprintf (buf, "%Le", x.value) < 0
|| !strisnan (buf, 0, strlen (buf)))
result |= 32;
if (sprintf (buf, "%Lg", x.value) < 0
|| !strisnan (buf, 0, strlen (buf)))
result |= 32;
}
{ /* Pseudo-Denormal. */
static union { unsigned int word[4]; long double value; } x =
{ LDBL80_WORDS (0x0000, 0x83333333, 0x00000000) };
if (sprintf (buf, "%Lf", x.value) < 0
|| !strisnan (buf, 0, strlen (buf)))
result |= 64;
if (sprintf (buf, "%Le", x.value) < 0
|| !strisnan (buf, 0, strlen (buf)))
result |= 64;
if (sprintf (buf, "%Lg", x.value) < 0
|| !strisnan (buf, 0, strlen (buf)))
result |= 64;
}
#endif
return result;
}