]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
factor: 25% speed-up, on output
authorJim Meyering <meyering@redhat.com>
Tue, 18 Sep 2012 06:26:17 +0000 (08:26 +0200)
committerJim Meyering <meyering@redhat.com>
Thu, 4 Oct 2012 20:09:00 +0000 (22:09 +0200)
* 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

index 84d9721c4b1d0246290f0c2c658993e652a78464..1ca581227633f87b62d91ef0d8b3229a61dda0b8 100644 (file)
@@ -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])
     {