Subject: Re: bin/30600
To: None <,>
From: Christian Biere <>
List: netbsd-bugs
Date: 06/27/2005 00:11:02
The following reply was made to PR bin/30600; it has been noted by GNATS.

From: Christian Biere <>
Subject: Re: bin/30600
Date: Mon, 27 Jun 2005 02:10:00 +0200

 I'd be surprised if the "if" in loop causes any noticeable slow-down. The
 suggested variant modifies a variable while passing it as parameter. I
 consider that bad practise.
 The additional putchar() in the original variant may possibly cause a minor
 slow-down at least that should weigh much more than the "if". My preferred
 version is as follows.
 for (/* NOTHING */; *argv; argv++)
   (void)printf(argv[1] ? "%s " : "%s", argv[0]);
 It doesn't cause any additional call. The "if" is still there. Another
 common way is using "%s%s" as format string whereas the last "%s" takes
 " " or "". That would be more work for printf().
 On the other hand, this one is probably still faster:
 if (*argv) {
 	(void)fputs(*argv, stdout);
    	while (*++argv) {
 		(void)putchar(' ');
 		(void)fputs(*argv, stdout);
 Interestingly, FreeBSD uses a much more complicated version. If you
 care that much about the performance of /bin/echo you might want to
 check that one.