Mail Archives: djgpp/2002/10/12/05:29:02
> From: "Leonid Pauzner" <uue AT pauzner DOT dnttm DOT ru>
> Date: Sat, 12 Oct 2002 02:35:20 +0400 (MSD)
>
> I am curious about the profile (attached below) I get from my program:
> a lot of time spent in getenv, days_to_years, timesub etc.
It's impossible to tell anything specific without seeing your
program, or at least having a vague idea about what it does.
In general, time functions _are_ heavy, since the computations are
non-trivial and require iterations in some cases. You shoulod try to
avoid calling time functions in inner loops of your program.
> Looking the libc sources (djlsr203.zip) I got an impression that
> 1) getenv implemented ineffectively - no hashing
How many environment variables do you have on your system? Unless you
have many thousands, I think hashing will not improve things in any
significant manner.
> 2) getenv heavily used by timer functions for timezone info
> (TZ, TZDIR, etc. - seems things are stored in static
> variables but probably not in all places?)
Only once: the time functions cache the values of environment
variables. If your program changes the environment a lot (by calling
putenv or setenv, for example), then caching could be ineffective,
since each time the environment changes, time functions must see if
some of their variables changed as well, and take note. This is so
that setting TZ to a different value is correctly handled.
> 4) I was unable to link my program with profiled libc version
You don't need to do that. Just pull the sources of the functions you
want to profile from the library, put them into your program, and
rebuild with -pg.
- Raw text -