Re: approximating division by a million Re: Why not POSIX time_t?

2002-07-16 Thread Brian Pane
Bill Stoddard wrote: Work up a patch to the apr_time macros and I'll benchmark it. This should be an easy and non intrusive thing to do. I tried to create a patch yesterday, but no luck. Given the wide range of values over which the macro has to work, I couldn't come up with with a macro that was

RE: approximating division by a million Re: Why not POSIX time_t?

2002-07-16 Thread Bill Stoddard
ject: approximating division by a million Re: Why not POSIX time_t? > > > Building upon Cliff's formulas, here's another idea > for doing faster conversions of the current apr_time_t > format to seconds: > > What we want is t/100 > > What we can do easily i

Re: approximating division by a million Re: Why not POSIX time_t?

2002-07-16 Thread Brian Pane
Ben Laurie wrote: Brian Pane wrote: Building upon Cliff's formulas, here's another idea for doing faster conversions of the current apr_time_t format to seconds: What we want is t/100 What we can do easily is t/1048576 But what can we add to t/1048576 to approximate t/100? If I solve for 'C

Re: approximating division by a million Re: Why not POSIX time_t?

2002-07-16 Thread Ben Laurie
Brian Pane wrote: Building upon Cliff's formulas, here's another idea for doing faster conversions of the current apr_time_t format to seconds: What we want is t/100 What we can do easily is t/1048576 But what can we add to t/1048576 to approximate t/100? If I solve for 'C' in t/100 =

Re: Why not POSIX time_t?

2002-07-15 Thread Brian Pane
Cliff Woolley wrote: On Mon, 15 Jul 2002, Brian Pane wrote: (seconds << 20) + microseconds Yeah, but addition and subtraction of the resulting scalars would require just as many carry/underflow checks as a structure would... You can rely on normal scalar arithmetic to handle the carry. T

Re: Why not POSIX time_t?

2002-07-15 Thread Brian Pane
Cliff Woolley wrote: On Mon, 15 Jul 2002, Cliff Woolley wrote: realsecs = 22/21 * (realusecs >> 20) + 22/21; realsecs = 44/21 * (realusecs >> 20); I'm obviously on crack. :) That last line is of course totally wrong and shouldn't have been there. :) So what we really end up with is this

approximating division by a million Re: Why not POSIX time_t?

2002-07-15 Thread Brian Pane
Building upon Cliff's formulas, here's another idea for doing faster conversions of the current apr_time_t format to seconds: What we want is t/100 What we can do easily is t/1048576 But what can we add to t/1048576 to approximate t/100? If I solve for 'C' in t/100 = t/1048576 + t/C I

Re: Why not POSIX time_t?

2002-07-15 Thread Justin Erenkrantz
On Mon, Jul 15, 2002 at 03:48:55PM -0400, Cliff Woolley wrote: > So it's something close to: > > realsecs = ((realusecs >> 20) + (realsecs/22) + 1); > > Which simplifies out as: > > realsecs = 22/21 * ((realusecs >> 20) + 1); > realsecs = 22/21 * (realusecs >> 20) + 22/21; > realsecs = 44/21 * (

Re: Why not POSIX time_t?

2002-07-15 Thread William A. Rowe, Jr.
At 02:15 PM 7/15/2002, Brian Pane wrote: Bill Stoddard wrote: Cliff demonstrates that there is significant loss of accuracy using just a shift. I believe (faith? :-) that there is a simple solution to this. Don't know what it is just now though... I think the simple solution is to pack the data int

Re: approximating division by a million Re: Why not POSIX time_t?

2002-07-15 Thread Brian Pane
Cliff Woolley wrote: On Mon, 15 Jul 2002, Brian Pane wrote: seconds = (t >> 20) + (t >> 24) That probably isn't accurate enough, but you get the basic idea: sum a couple of t/(2^n) terms to approximate t/100. What do you think? Sounds like the right idea. But I'm still not sure this i

Re: approximating division by a million Re: Why not POSIX time_t?

2002-07-15 Thread Cliff Woolley
On Mon, 15 Jul 2002, Brian Pane wrote: > seconds = (t >> 20) + (t >> 24) > > That probably isn't accurate enough, but you get the basic idea: > sum a couple of t/(2^n) terms to approximate t/100. > > What do you think? Sounds like the right idea. But I'm still not sure this isn't too compli

RE: Why not POSIX time_t?

2002-07-15 Thread Cliff Woolley
On Mon, 15 Jul 2002, Ryan Bloom wrote: > Ok, cool. I thought I had forgotten something insanely simple about > basic math. Phew. :-D Programming, calculus, theory of computation, that stuff is easy. Arithmetic and algebra, that's hard. =-] You know you're in trouble when you can't even ma

RE: Why not POSIX time_t?

2002-07-15 Thread Ryan Bloom
> On Mon, 15 Jul 2002, Cliff Woolley wrote: > > > realsecs = 22/21 * (realusecs >> 20) + 22/21; > > realsecs = 44/21 * (realusecs >> 20); > > I'm obviously on crack. :) > > That last line is of course totally wrong and shouldn't have been there. > :) Ok, cool. I thought I had forgotten someth

RE: Why not POSIX time_t?

2002-07-15 Thread Cliff Woolley
On Mon, 15 Jul 2002, Cliff Woolley wrote: > realsecs = 22/21 * (realusecs >> 20) + 22/21; > realsecs = 44/21 * (realusecs >> 20); I'm obviously on crack. :) That last line is of course totally wrong and shouldn't have been there. :)

RE: Why not POSIX time_t?

2002-07-15 Thread Cliff Woolley
On Mon, 15 Jul 2002, Bill Stoddard wrote: > Cliff demonstrates that there is significant loss of accuracy using just a > shift. I believe (faith? :-) that there is a simple solution to this. Don't > know what it is just now though... More numerical musings: Without compensation: 1-21 seconds co

Re: Why not POSIX time_t?

2002-07-15 Thread Cliff Woolley
On Mon, 15 Jul 2002, Brian Pane wrote: > (seconds << 20) + microseconds Yeah, but addition and subtraction of the resulting scalars would require just as many carry/underflow checks as a structure would... I mean, that's all that really is: a bitfield. --Cliff

Re: Why not POSIX time_t?

2002-07-15 Thread Brian Pane
Bill Stoddard wrote: Cliff demonstrates that there is significant loss of accuracy using just a shift. I believe (faith? :-) that there is a simple solution to this. Don't know what it is just now though... I think the simple solution is to pack the data into the apr_time_t using (seconds << 20)

RE: Why not POSIX time_t?

2002-07-15 Thread Ryan Bloom
On Mon, 15 Jul 2002, Bill Stoddard wrote: > > >>3. 64-bit shifts to get approximate seconds > > >> (fast, but loss of accuracy) > > >> > > >> > > > > > >If you convert from microseconds to integer seconds (which is what httpd > > >requires), you loose -resolution- no matter how you do it

RE: Why not POSIX time_t?

2002-07-15 Thread Bill Stoddard
> >>3. 64-bit shifts to get approximate seconds > >> (fast, but loss of accuracy) > >> > >> > > > >If you convert from microseconds to integer seconds (which is what httpd > >requires), you loose -resolution- no matter how you do it. If > the accuracy > >you loose is smaller than the reso

Re: Why not POSIX time_t?

2002-07-15 Thread Brian Pane
Bill Stoddard wrote: Under this proposal, the sequence of time operations in an httpd request would look like: 1. gettimeofday (fast, no loss of accuracy) We cannot avoid this, right? Right (but it's fast enough that we don't need to worry about it). 2. 64-bit multiplication to bui

RE: Why not POSIX time_t?

2002-07-15 Thread Bill Stoddard
> On Mon, 15 Jul 2002, Bill Stoddard wrote: > > > > 1. gettimeofday > > >(fast, no loss of accuracy) > > We cannot avoid this, right? > > Right. > > > > > > 2. 64-bit multiplication to build an apr_time_t > > >(slow (on lots of current platforms), no loss of accuracy) > > >

RE: Why not POSIX time_t?

2002-07-15 Thread Cliff Woolley
On Mon, 15 Jul 2002, Bill Stoddard wrote: > > 1. gettimeofday > >(fast, no loss of accuracy) > We cannot avoid this, right? Right. > > > 2. 64-bit multiplication to build an apr_time_t > >(slow (on lots of current platforms), no loss of accuracy) > > Do we eliminate this

RE: Why not POSIX time_t?

2002-07-15 Thread Bill Stoddard
> Bill Stoddard wrote: > > >New proposal... leave apr_time_t exactly as it is. The > performance problem > >is with how we are converting an apr_time_t into a value with 1 second > >resolution (ie, doing 64 bit divisions). I propose we introduce some new > >macros (or functions) to efficiently re

Re: Why not POSIX time_t?

2002-07-15 Thread Jim Jagielski
+1 (on both :) ) David Reid wrote: > > +1 from me. Let's finish this nonsense! > > david > > > New proposal... leave apr_time_t exactly as it is. The performance > problem > > is with how we are converting an apr_time_t into a value with 1 second > > resolution (ie, doing 64 bit divisions). I

Re: Why not POSIX time_t?

2002-07-15 Thread Brian Pane
Bill Stoddard wrote: New proposal... leave apr_time_t exactly as it is. The performance problem is with how we are converting an apr_time_t into a value with 1 second resolution (ie, doing 64 bit divisions). I propose we introduce some new macros (or functions) to efficiently remove resolution fr

RE: Why not POSIX time_t?

2002-07-15 Thread Ryan Bloom
> To: APR Dev List > Subject: Re: Why not POSIX time_t? > > +1 from me. Let's finish this nonsense! > > david > > > New proposal... leave apr_time_t exactly as it is. The performance > problem > > is with how we are converting an apr_time_t into a va

Re: Why not POSIX time_t?

2002-07-15 Thread David Reid
+1 from me. Let's finish this nonsense! david > New proposal... leave apr_time_t exactly as it is. The performance problem > is with how we are converting an apr_time_t into a value with 1 second > resolution (ie, doing 64 bit divisions). I propose we introduce some new > macros (or functions)

RE: Why not POSIX time_t?

2002-07-15 Thread Bill Stoddard
New proposal... leave apr_time_t exactly as it is. The performance problem is with how we are converting an apr_time_t into a value with 1 second resolution (ie, doing 64 bit divisions). I propose we introduce some new macros (or functions) to efficiently remove resolution from apr_time_t and do

RE: Why not POSIX time_t?

2002-07-15 Thread Bill Stoddard
> > >>If you mean using only second-resolution times, that's an option, > > >>but not for the httpd. One of the big problems with 1.3 was that > > >>the request time was only stored with 1-second resolution. We used > > >>to have to add in custom, redundant time lookups to get better > > >>resol

RE: Why not POSIX time_t?

2002-07-15 Thread Ryan Bloom
> >>If you mean using only second-resolution times, that's an option, > >>but not for the httpd. One of the big problems with 1.3 was that > >>the request time was only stored with 1-second resolution. We used > >>to have to add in custom, redundant time lookups to get better > >>resolution whene

Re: Why not POSIX time_t?

2002-07-15 Thread Brian Pane
[EMAIL PROTECTED] wrote: On Sun, 14 Jul 2002, Brian Pane wrote: Ryan Bloom wrote: BTW, this whole conversation started because we wanted to speed up Apache. Has anybody considered taking a completely different tack to solve this problem? If you mean using only second-resolution t

Re: Why not POSIX time_t?

2002-07-15 Thread Brian Pane
Justin Erenkrantz wrote: On Sun, Jul 14, 2002 at 07:42:09PM -0700, Brian Pane wrote: It's a little more efficient if you put the result in a struct rather than a scalar, but you still have to do the carry from the seconds field to the microseconds field if time1.tv_usec < time2.tv_usec. Minimal

Re: Why not POSIX time_t?

2002-07-15 Thread rbb
On Sun, 14 Jul 2002, Brian Pane wrote: > Ryan Bloom wrote: > > >BTW, this whole conversation started because we wanted to speed up > >Apache. Has anybody considered taking a completely different tack to > >solve this problem? > > > > If you mean using only second-resolution times, that's an o

Re: Why not POSIX time_t?

2002-07-15 Thread Brian Pane
Ryan Bloom wrote: BTW, this whole conversation started because we wanted to speed up Apache. Has anybody considered taking a completely different tack to solve this problem? If you mean using only second-resolution times, that's an option, but not for the httpd. One of the big problems with 1.

Re: Why not POSIX time_t?

2002-07-15 Thread William A. Rowe, Jr.
At 10:56 PM 7/14/2002, Justin Erenkrantz wrote: On Sun, Jul 14, 2002 at 07:42:09PM -0700, Brian Pane wrote: > It's a little more efficient if you put the result in > a struct rather than a scalar, but you still have to do > the carry from the seconds field to the microseconds field > if time1.tv_us

Re: Why not POSIX time_t?

2002-07-15 Thread Justin Erenkrantz
On Sun, Jul 14, 2002 at 07:42:09PM -0700, Brian Pane wrote: > It's a little more efficient if you put the result in > a struct rather than a scalar, but you still have to do > the carry from the seconds field to the microseconds field > if time1.tv_usec < time2.tv_usec. Minimally, subtraction > of

Re: Why not POSIX time_t?

2002-07-15 Thread Brian Pane
Aaron Bannert wrote: The reason we don't use a struct (timeval or any variant thereof) is that doing addition and subtraction on the struct is much slower, more complicated, and (if people try to do their own match on the struct directly) more error-prone than doing the same ops on a scalar. H

RE: Why not POSIX time_t?

2002-07-15 Thread Ryan Bloom
For clarity, there is only one reason that we aren't just using POSIX's time_t. While Windows has time_t, it doesn't use time_t's internally. Instead, it uses a completely different epoch with 100 nano-second resolution. The only other reason for apr_time_t is to get usec resolution. > From: Aa

Re: Why not POSIX time_t?

2002-07-15 Thread William A. Rowe, Jr.
At 09:35 PM 7/14/2002, Aaron Bannert wrote: On Sun, Jul 14, 2002 at 07:27:04PM -0700, Brian Pane wrote: How exactly is the subtraction slower?I'm not at all sure what you mean by people matching on the struct directly... For addition... rtm.sec = tm1.sec + tm2.sec; rtm.usec = tm1.usec + tm2.usec; i

Re: Why not POSIX time_t?

2002-07-15 Thread Aaron Bannert
On Sun, Jul 14, 2002 at 07:27:04PM -0700, Brian Pane wrote: > You're thinking of timeval; time_t is just a long int containing > seconds since the start of the epoch. Yes, thanks. :) > The reason we don't use a struct (timeval or any variant thereof) > is that doing addition and subtraction on th

Re: Why not POSIX time_t?

2002-07-15 Thread Brian Pane
Aaron Bannert wrote: Can someone remind me what the reasons are that we don't use a struct with separate elements for seconds and microseconds, ala time_t? You're thinking of timeval; time_t is just a long int containing seconds since the start of the epoch. The reason we don't use a struct (tim