[PATCH 5/6] vfprintf: Introduce printf_positional function
Florian Weimer
fweimer@redhat.com
Fri Mar 6 12:58:00 GMT 2015
On 03/01/2015 10:16 PM, Florian Weimer wrote:
> This splits a considerable chunk of code from the main vfprintf
> function. This will make it easier to remove the use of extend_alloca
> from the positional argument handling code.
Inspection of the generated assembly on x86_64 shows that splitting the
two functions helps GCC 4.9 with register allocation; there are fewer
spills.
I used the following totally made-up benchmark to see if there is a
performance regression.
#define _GNU_SOURCE
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
#include <err.h>
#ifdef POSITIONAL
#define FORMAT " %1$d: %2$c%3$c%4$c%5$c%6$c %7$20s %8$f (%9$02x)\n"
#else
#define FORMAT " %d: %c%c%c%c%c %20s %f (%02x)\n"
#endif
int
main (int argc, char **argv)
{
int iterations = atoi (argv[1]);
struct timespec ts_start;
if (clock_gettime (CLOCK_MONOTONIC_RAW, &ts_start) != 0)
err (1, "clock_gettime");
for (int i = 0; i < iterations; ++i)
{
char buf[256];
sprintf (buf, FORMAT,
1001, '1', '2', '3', '4', '5', "string", 1.5, 0x1234);
}
struct timespec ts_end;
if (clock_gettime (CLOCK_MONOTONIC_RAW, &ts_end) != 0)
err (1, "clock_gettime");
printf ("%f\n",
ts_end.tv_sec + ts_end.tv_nsec * 1e-9
- ts_start.tv_sec - ts_start.tv_nsec * 1e-9);
return 0;
}
t-test without -DPOSITONAL (50 runs):
data: before and after
t = 3.8079, df = 91.121, p-value = 0.0002539
alternative hypothesis: true difference in means is not equal to 0
95 percent confidence interval:
0.01236649 0.03933739
sample estimates:
mean of x mean of y
1.0200367 0.9941847
t-test with -DPOSITIONAL=1 (50 runs):
data: before and after
t = 5.2566, df = 65.134, p-value = 1.74e-06
alternative hypothesis: true difference in means is not equal to 0
95 percent confidence interval:
0.06132365 0.13646651
sample estimates:
mean of x mean of y
1.749552 1.650657
--
Florian Weimer / Red Hat Product Security
More information about the Libc-alpha
mailing list