diff options
author | Dan McGee <dan@archlinux.org> | 2011-10-03 10:54:08 -0500 |
---|---|---|
committer | Dan McGee <dan@archlinux.org> | 2011-10-13 20:59:16 -0500 |
commit | 8605284e0d1b70d9845ca4c6362d7d451f503d32 (patch) | |
tree | 91068c025f1b0c38d14a13132208dddf2b5aee1e /src/pacman/callback.c | |
parent | 9934052b54fd4dcd2339a2beb87ccc81b5e144bd (diff) |
Use puts() instead of no-op printf() where applicable
This replaces several printf calls of the following styles:
printf("%s", ...);
printf("some fixed string");
printf("x");
We can use either fputs() or putchar() here to do the same thing
without incurring the overhead of the printf format parser.
The biggest gain here comes when we are calling the print function in a
loop repeatedly; notably when printing local package files.
$ /usr/bin/time ./pacman-before -Ql | md5sum
0.25user 0.04system 0:00.30elapsed 98%CPU
$ /usr/bin/time ./pacman-after -Ql | md5sum
0.17user 0.06system 0:00.25elapsed 94%CPU
$ /usr/bin/time ./pacman-before -Qlq | md5sum
0.20user 0.05system 0:00.26elapsed 98%CPU
$ /usr/bin/time ./pacman-after -Qlq | md5sum
0.15user 0.05system 0:00.23elapsed 93%CPU
So '-Ql' shows a 17% improvement while '-Qlq' shows a 13% improvement on
382456 total files.
Signed-off-by: Dan McGee <dan@archlinux.org>
Diffstat (limited to 'src/pacman/callback.c')
-rw-r--r-- | src/pacman/callback.c | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/src/pacman/callback.c b/src/pacman/callback.c index 7235d394..80db402a 100644 --- a/src/pacman/callback.c +++ b/src/pacman/callback.c @@ -228,7 +228,7 @@ void cb_event(alpm_event_t event, void *data1, void *data2) printf(_("failed.\n")); break; case ALPM_EVENT_SCRIPTLET_INFO: - printf("%s", (char *)data1); + fputs((const char *)data1, stdout); break; case ALPM_EVENT_RETRIEVE_START: printf(_(":: Retrieving packages from %s...\n"), (char *)data1); @@ -495,7 +495,7 @@ void cb_progress(alpm_progress_t event, const char *pkgname, int percent, alpm_list_t *i = NULL; on_progress = 0; for(i = output; i; i = i->next) { - printf("%s", (char *)i->data); + fputs((const char *)i->data, stdout); } fflush(stdout); FREELIST(output); |