From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 14071 invoked by alias); 7 Feb 2014 22:45:16 -0000 Mailing-List: contact cygwin-help@cygwin.com; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner@cygwin.com Mail-Followup-To: cygwin@cygwin.com Received: (qmail 14056 invoked by uid 89); 7 Feb 2014 22:45:15 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=1.0 required=5.0 tests=AWL,BAYES_00,FREEMAIL_FROM,KAM_COUK,RCVD_IN_BL_SPAMCOP_NET,SPF_PASS autolearn=no version=3.3.2 X-HELO: out.ipsmtp2nec.opaltelecom.net Received: from out.ipsmtp2nec.opaltelecom.net (HELO out.ipsmtp2nec.opaltelecom.net) (62.24.202.74) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (CAMELLIA256-SHA encrypted) ESMTPS; Fri, 07 Feb 2014 22:45:14 +0000 X-SMTPAUTH: drstacey@tiscali.co.uk X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: ApMBAHRh9VJPRtO6/2dsb2JhbAANTMAFgwmBIYMZAQEBBCcRQBELGAkWDwkDAgECAUUTCAEBsnehYxePBBaEIgEDrDuBPg X-IPAS-Result: ApMBAHRh9VJPRtO6/2dsb2JhbAANTMAFgwmBIYMZAQEBBCcRQBELGAkWDwkDAgECAUUTCAEBsnehYxePBBaEIgEDrDuBPg Received: from 79-70-211-186.dynamic.dsl.as9105.com (HELO [192.168.1.4]) ([79.70.211.186]) by out.ipsmtp2nec.opaltelecom.net with ESMTP; 07 Feb 2014 22:45:07 +0000 Message-ID: <52F561EE.8090806@tiscali.co.uk> Date: Fri, 07 Feb 2014 22:45:00 -0000 From: David Stacey User-Agent: Mozilla/5.0 (X11; Linux x86_64; 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> <52F553AA.9090500@cygwin.com> In-Reply-To: <52F553AA.9090500@cygwin.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-IsSubscribed: yes X-SW-Source: 2014-02/txt/msg00153.txt.bz2 On 07/02/14 21:44, Larry Hall (Cygwin) wrote: > 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 >> #include >> #include >> >> 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. ;-) > I thought the point of the programme /was/ to call getpwnam() a million times. Time this as accurately as you can. Then, with a quick division, you get the time for one call. Dave. -- 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