delorie.com/archives/browse.cgi | search |
X-Recipient: | archive-cygwin AT delorie DOT 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:mime-version:to:subject | |
:references:in-reply-to:content-type:content-transfer-encoding; | |
q=dns; s=default; b=JTScjd1FiHhx3mTivd0hvlvirsI3+xbDJEU7ogXbBw6 | |
SYeOkbXPj1GbJ5Ky9oMA+5T1C+dsi4gg+eheMlkFv+9ZzL6Wd31ZImMHsswQWJ3S | |
Hzbia4kw+NaXNxQTj1VxXTCgdq3iQ+3pzkdNZvNMlJFW9yS7hepI+jv2OquE/0D0 | |
= | |
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:mime-version:to:subject | |
:references:in-reply-to:content-type:content-transfer-encoding; | |
s=default; bh=CGyIatX2x+Mc54acWxD0g08khC4=; b=EDfGNNZe4qJOJD5Kr | |
SnYCxO9PgvotNolIlhkTvIrmcfE8PFRNA9lwUMKGMFNV86QpTge0RnBSDM2TTG6B | |
hZY7osviH3+4DD5N2G5cDPLp5EzSAXeFidNh3wVNTf/GTo4N5CbL3XcgnAQ9r94Z | |
1Z/WRyla6ZdAjbAA0BX0tcWP1s= | |
Mailing-List: | contact cygwin-help AT cygwin DOT com; run by ezmlm |
List-Id: | <cygwin.cygwin.com> |
List-Subscribe: | <mailto:cygwin-subscribe AT cygwin DOT com> |
List-Archive: | <http://sourceware.org/ml/cygwin/> |
List-Post: | <mailto:cygwin AT cygwin DOT com> |
List-Help: | <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs> |
Sender: | cygwin-owner AT cygwin DOT com |
Mail-Followup-To: | cygwin AT cygwin DOT com |
Delivered-To: | mailing list cygwin AT cygwin DOT com |
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 |
X-SMTPAUTH: | drstacey AT tiscali DOT co DOT uk |
X-IronPort-Anti-Spam-Filtered: | true |
X-IronPort-Anti-Spam-Result: | ApMBAHRh9VJPRtO6/2dsb2JhbAANTMAFgwmBIYMZAQEBBCcRQBELGAkWDwkDAgECAUUTCAEBsnehYxePBBaEIgEDrDuBPg |
X-IPAS-Result: | ApMBAHRh9VJPRtO6/2dsb2JhbAANTMAFgwmBIYMZAQEBBCcRQBELGAkWDwkDAgECAUUTCAEBsnehYxePBBaEIgEDrDuBPg |
Message-ID: | <52F561EE.8090806@tiscali.co.uk> |
Date: | Fri, 07 Feb 2014 22:45:02 +0000 |
From: | David Stacey <drstacey AT tiscali DOT co DOT uk> |
User-Agent: | Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.3.0 |
MIME-Version: | 1.0 |
To: | cygwin AT cygwin DOT com |
Subject: | Re: get rid of getpwent? (Was: cygwin-1.7.28 getpwent header declaration changes ?) |
References: | <52F339CA DOT 5070305 AT gmail DOT com> <20140206090117 DOT GD2821 AT calimero DOT vinschen DOT de> <52F361C5 DOT 3000807 AT gmail DOT com> <20140206141321 DOT GI2821 AT calimero DOT vinschen DOT de> <52F40208 DOT 5030901 AT etr-usa DOT com> <20140207094917 DOT GN2821 AT calimero DOT vinschen DOT de> <52F53D7C DOT 5050201 AT etr-usa DOT com> <52F553AA DOT 9090500 AT cygwin DOT com> |
In-Reply-To: | <52F553AA.9090500@cygwin.com> |
X-IsSubscribed: | yes |
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 <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. ;-) > 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
webmaster | delorie software privacy |
Copyright © 2019 by DJ Delorie | Updated Jul 2019 |