This is the mail archive of the
cygwin
mailing list for the Cygwin project.
Re: get rid of getpwent? (Was: cygwin-1.7.28 getpwent header declaration changes ?)
- From: Andrey Repin <anrdaemon at yandex dot ru>
- To: "Larry Hall (Cygwin)" <cygwin at cygwin dot com>
- Date: Sat, 8 Feb 2014 04:40:40 +0400
- Subject: Re: get rid of getpwent? (Was: cygwin-1.7.28 getpwent header declaration changes ?)
- Authentication-results: sourceware.org; auth=none
- 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> <52F561EE dot 8090806 at tiscali dot co dot uk> <52F56E92 dot 3070309 at cygwin dot com>
- Reply-to: Andrey Repin <cygwin at cygwin dot com>
Greetings, Larry Hall (Cygwin)!
>>>> 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.
> 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