From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 11853 invoked by alias); 8 Feb 2014 00:50:25 -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 11843 invoked by uid 89); 8 Feb 2014 00:50:24 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=4.1 required=5.0 tests=AWL,BAYES_50,FREEMAIL_FROM,KAM_THEBAT,SPF_SOFTFAIL autolearn=no version=3.3.2 X-HELO: smtpback.ht-systems.ru Received: from smtpback.ht-systems.ru (HELO smtpback.ht-systems.ru) (78.110.50.181) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-SHA encrypted) ESMTPS; Sat, 08 Feb 2014 00:50:21 +0000 Received: from [91.78.166.180] (helo=darkdragon.lan) by smtp.ht-systems.ru with esmtpa (Exim 4.80.1) (envelope-from ) id 1WBw7R-0001yP-WC for cygwin@cygwin.com; Sat, 08 Feb 2014 04:50:06 +0400 Received: from [192.168.1.10] (HELO daemon2.darkdragon.lan) by daemon2 (Office Mail Server 0.8.12 build 08053101) with SMTP; Sat, 08 Feb 2014 00:40:40 -0000 Date: Sat, 08 Feb 2014 00:50:00 -0000 From: Andrey Repin Reply-To: Andrey Repin Message-ID: <675717060.20140208044040@mtu-net.ru> To: "Larry Hall (Cygwin)" Subject: Re: get rid of getpwent? (Was: cygwin-1.7.28 getpwent header declaration changes ?) In-Reply-To: <52F56E92.3070309@cygwin.com> 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> <52F561EE.8090806@tiscali.co.uk> <52F56E92.3070309@cygwin.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-IsSubscribed: yes X-SW-Source: 2014-02/txt/msg00155.txt.bz2 Greetings, Larry Hall (Cygwin)! >>>> 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. > Hm, I missed that he summarized with _microseconds_, even though I quoted > that too in my response. :-( > My average was much closer to 2 microseconds per call but that could be > machine differences. > In any case, sorry for the noise. In either case, repeatedly requesting the same record in a short amount of time will only test the system level cache. -- WBR, Andrey Repin (anrdaemon@yandex.ru) 08.02.2014, <04:39> Sorry for my terrible english... -- 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