X-Recipient: archive-cygwin@delorie.com
DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id
	:list-unsubscribe:list-subscribe:list-archive:list-post
	:list-help:sender:message-id:date:from:reply-to:mime-version:to
	:subject:references:in-reply-to:content-type
	:content-transfer-encoding; q=dns; s=default; b=Bi0aPyst/3I3REv+
	hDvDbaXQtH4ut0bMF+nZxcAOihqGhOtnq8esTEVDycHkzf2FaKoGCmdzCpf/U2p+
	oGP3mP1L+YXijzDPGXJCH2Zjyq64Po6BYwb/9Js9AU/EKigpgwefPRinjd95itO4
	WV2uwDrDLQwsDdASOnt4wZkicFo=
DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id
	:list-unsubscribe:list-subscribe:list-archive:list-post
	:list-help:sender:message-id:date:from:reply-to:mime-version:to
	:subject:references:in-reply-to:content-type
	:content-transfer-encoding; s=default; bh=VKnCYJoRP+EFHz2No9Q8Oz
	oqgMU=; b=DRuprjfsyEa0xSyKxj4w8QLvHB8ov7HosuDGPjyi+oFo7H+wqe/DK9
	8Wh2JeOYAYfVYegRwSbirKGdv9OgtWC5IazoanZrxqWp9HR6QnyR//Gd1dE67LEX
	jYqybehDjdAWR0Rd/KkvcxgfTqtVDtPlYU7GqLNY/MOQcOqpUuEnI=
Mailing-List: contact cygwin-help@cygwin.com; run by ezmlm
List-Id: <cygwin.cygwin.com>
List-Subscribe: <mailto:cygwin-subscribe@cygwin.com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin@cygwin.com>
List-Help: <mailto:cygwin-help@cygwin.com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner@cygwin.com
Mail-Followup-To: cygwin@cygwin.com
Delivered-To: mailing list cygwin@cygwin.com
Authentication-Results: sourceware.org; auth=none
X-Virus-Found: No
X-Spam-SWARE-Status: No, score=-0.6 required=5.0 tests=AWL,BAYES_05,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.2
X-HELO: vms173017pub.verizon.net
Message-id: <52F553AA.9090500@cygwin.com>
Date: Fri, 07 Feb 2014 16:44:10 -0500
From: "Larry Hall (Cygwin)" <reply-to-list-only-lh@cygwin.com>
Reply-to: cygwin@cygwin.com
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:24.0) Gecko/20100101 Thunderbird/24.3.0
MIME-version: 1.0
To: cygwin@cygwin.com
Subject: Re: get rid of getpwent? (Was: cygwin-1.7.28 getpwent header declaration changes ?)
References: <52F339CA.5070305@gmail.com> <20140206090117.GD2821@calimero.vinschen.de> <52F361C5.3000807@gmail.com> <20140206141321.GI2821@calimero.vinschen.de> <52F40208.5030901@etr-usa.com> <20140207094917.GN2821@calimero.vinschen.de> <52F53D7C.5050201@etr-usa.com>
In-reply-to: <52F53D7C.5050201@etr-usa.com>
Content-type: text/plain; charset=ISO-8859-1; format=flowed
Content-transfer-encoding: 7bit

On 2/7/2014 3:09 PM, Warren Young wrote:
> This takes 7.1 seconds on my system, with a 12-line /etc/passwd file:
>
>       #include <pwd.h>
>       #include <stdio.h>
>       #include <stdlib.h>
>
>       int main(int argc, const char* argv[])
>       {
>           int i;
>           const char* user = argv[1];
>
>           if (!user) {
>               printf("usage: %s username\n", argv[0]);
>               exit(1);
>           }
>
>           for (i = 0; i < 1000000; ++i) {
>               struct passwd* pw = getpwnam(user);
>               if (!pw) {
>                   printf("User %s doesn't exist!\n", user);
>                   exit(2);
>               }
>               else if (i == 0) {
>                   printf("User %s is UID %d\n", user, pw->pw_uid);
>               }
>           }
>       }
>
> So, each getpwnam() call takes 7.1 microseconds on average.

I think you forgot to put an "exit(0);" after the last printf().  Without
it, you're checking for the same user a million times, which is certainly
going to take a little time. ;-)

-- 
Larry

_____________________________________________________________________

A: Yes.
 > Q: Are you sure?
 >> A: Because it reverses the logical flow of conversation.
 >>> Q: Why is top posting annoying in email?

--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

