Andres Freund <and...@anarazel.de> writes:
> So when using pg's snprintf() to print a single floating point number
> with precision, we get nearly a 10% boost.

I just tested that using my little standalone testbed, and I failed
to replicate the result.  I do see that strfromd is slightly faster,
but it's just a few percent measuring snprintf.c in isolation --- in
the overall context of COPY, I don't see how you get to 10% net savings.

So I continue to think there's something fishy about your test case.

BTW, so far as I can tell on F28, strfromd isn't exposed without
"-D__STDC_WANT_IEC_60559_BFP_EXT__", which seems fairly scary;
what else does that affect?

                        regards, tom lane

diff --git a/src/port/snprintf.c b/src/port/snprintf.c
index b9b6add..f75369c 100644
--- a/src/port/snprintf.c
+++ b/src/port/snprintf.c
@@ -1137,17 +1137,19 @@ fmtfloat(double value, char type, int forcesign, int leftjust,
 		zeropadlen = precision - prec;
 		fmt[0] = '%';
 		fmt[1] = '.';
-		fmt[2] = '*';
-		fmt[3] = type;
-		fmt[4] = '\0';
-		vallen = sprintf(convert, fmt, prec, value);
+		fmt[2] = (prec / 100) + '0';
+		fmt[3] = ((prec % 100) / 10) + '0';
+		fmt[4] = (prec % 10) + '0';
+		fmt[5] = type;
+		fmt[6] = '\0';
+		vallen = strfromd(convert, sizeof(convert), fmt, value);
 	}
 	else
 	{
 		fmt[0] = '%';
 		fmt[1] = type;
 		fmt[2] = '\0';
-		vallen = sprintf(convert, fmt, value);
+		vallen = strfromd(convert, sizeof(convert), fmt, value);
 	}
 	if (vallen < 0)
 		goto fail;

Reply via email to