From 06b7ed8051d07677572e074d3d45007f1282ed56 Mon Sep 17 00:00:00 2001 From: Jim Meyering Date: Tue, 18 Sep 2012 08:26:17 +0200 Subject: factor: 25% speed-up, on output * src/factor.c (print_factors_single): Use fputs and umaxtostr rather than printf with "%ju". This reduced the time required to compute and print the factors of the first 10^7 integers from over 8 seconds to 5.75s. Run this command: seq $((10**7)) | env time factor > /dev/null --- src/factor.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/factor.c b/src/factor.c index 84d9721c4..1ca581227 100644 --- a/src/factor.c +++ b/src/factor.c @@ -2272,7 +2272,11 @@ print_factors_single (uintmax_t t1, uintmax_t t0) for (unsigned int j = 0; j < factors.nfactors; j++) for (unsigned int k = 0; k < factors.e[j]; k++) - printf (" %ju", factors.p[j]); + { + char buf[INT_BUFSIZE_BOUND (uintmax_t)]; + putchar (' '); + fputs (umaxtostr (factors.p[j], buf), stdout); + } if (factors.plarge[1]) { -- cgit v1.2.3-70-g09d2