"Frank Behrens" <[EMAIL PROTECTED]> writes:

> Juliusz Chroboczek <[EMAIL PROTECTED]> wrote on 2 Dec 2007 16:02:
>> Any ideas to make timeval_cmp more efficient are warmly welcomed.
>
> In FreeBSD sources I read in sys/time.h
>
> #define timevalcmp(tvp, uvp, cmp)                                       \
>         (((tvp)->tv_sec == (uvp)->tv_sec) ?                             \
>             ((tvp)->tv_usec cmp (uvp)->tv_usec) :                       \
>             ((tvp)->tv_sec cmp (uvp)->tv_sec))
>
> It seems to have an diffent API and I don't know if it uses less operations
> on default path.

It looks like it could be significantly faster in the general case, but
possibly not if most of the compared times differ in the tv_sec field.

A non-macro variant could be something like

  static inline int
  timeval_before(struct timeval *t1, struct timeval *t2)
  {
      return (t1->tv_sec != t2->tv_sec ?
              t1->tv_sec  < t2->tv_sec :
              t1->tv_usec < t2->tv_usec);
  }

where the sense of the first test is switched to optimise for the >1s apart
case, as it is in current polipo.

But to be honest I'm surprised this function shows up at all, it's just a
few instructions in any case. I guess it means that polipo is quite zippy
already.


-j.


-------------------------------------------------------------------------
SF.Net email is sponsored by:
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://sourceforge.net/services/buy/index.php
_______________________________________________
Polipo-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/polipo-users

Reply via email to