Leap Years in the Date class

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Leap Years in the Date class

alex
Hi,

I was looking at date.cpp and noticed this [0]. I realize that 2200 is far off, but this section made me wince.

Is there any interest in (or reason against) redoing this section so that it lazily populates an array, instead of having one hard coded? I have some spare time this weekend.

[0] https://github.com/lballabio/quantlib/blob/master/QuantLib/ql/time/date.cpp#L208


Thanks,
Alex

------------------------------------------------------------------------------
Dive into the World of Parallel Programming The Go Parallel Website, sponsored
by Intel and developed in partnership with Slashdot Media, is your hub for all
things parallel software development, from weekly thought leadership blogs to
news, videos, case studies, tutorials and more. Take a look and join the
conversation now. http://goparallel.sourceforge.net/
_______________________________________________
QuantLib-dev mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-dev
Reply | Threaded
Open this post in threaded view
|

Re: Leap Years in the Date class

Peter Caspers-4
Hi Alex,

I am in favour of this. Just note that (at least) you would have to
take care about Date::yearOffset(...) and Date::maxSerialNumber(...)
as well when extending the range of possible dates. I am not sure if
there are other code places to consider, Luigi will be the right
person to answer that ultimately.

Apart from that I played around a bit and

boost::gregorian::gregorian_calendar::is_leap_year(y)

seems to be faster than the original ql code anyway (only 1900 is
treated different, ql is following the excel "convention" here). I
seem to observe a factor ql / boost of around 6.

And this

inline bool isLeap2(int y) {
    if(y%4 != 0) return false;
    if(y%100 != 0) return true;
    if(y%400 != 0) return false;
    return true;
}

is even faster (ql / isLeap2 = 40 ). Again be careful with 1900.

Best regards
Peter


On 22 March 2015 at 03:02, Alexander Lamana <[hidden email]> wrote:

> Hi,
>
> I was looking at date.cpp and noticed this [0]. I realize that 2200 is far
> off, but this section made me wince.
>
> Is there any interest in (or reason against) redoing this section so that it
> lazily populates an array, instead of having one hard coded? I have some
> spare time this weekend.
>
> [0]
> https://github.com/lballabio/quantlib/blob/master/QuantLib/ql/time/date.cpp#L208
>
>
> Thanks,
> Alex
>
> ------------------------------------------------------------------------------
> Dive into the World of Parallel Programming The Go Parallel Website,
> sponsored
> by Intel and developed in partnership with Slashdot Media, is your hub for
> all
> things parallel software development, from weekly thought leadership blogs
> to
> news, videos, case studies, tutorials and more. Take a look and join the
> conversation now. http://goparallel.sourceforge.net/
> _______________________________________________
> QuantLib-dev mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/quantlib-dev
>

------------------------------------------------------------------------------
Dive into the World of Parallel Programming The Go Parallel Website, sponsored
by Intel and developed in partnership with Slashdot Media, is your hub for all
things parallel software development, from weekly thought leadership blogs to
news, videos, case studies, tutorials and more. Take a look and join the
conversation now. http://goparallel.sourceforge.net/
_______________________________________________
QuantLib-dev mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-dev
Reply | Threaded
Open this post in threaded view
|

Re: Leap Years in the Date class

Peter Caspers-4
in which the perfomance numbers above depend a lot on the test loop
setup, the compiler seems to apply some clever optimizations when
using a "regular" year pattern as input to the leap year functions.
With random years, the factors are more like this

ql / boost = 1.0
ql / isLeap2 = 2.7

so not that impressive any more.


On 22 March 2015 at 09:54, Peter Caspers <[hidden email]> wrote:

> Hi Alex,
>
> I am in favour of this. Just note that (at least) you would have to
> take care about Date::yearOffset(...) and Date::maxSerialNumber(...)
> as well when extending the range of possible dates. I am not sure if
> there are other code places to consider, Luigi will be the right
> person to answer that ultimately.
>
> Apart from that I played around a bit and
>
> boost::gregorian::gregorian_calendar::is_leap_year(y)
>
> seems to be faster than the original ql code anyway (only 1900 is
> treated different, ql is following the excel "convention" here). I
> seem to observe a factor ql / boost of around 6.
>
> And this
>
> inline bool isLeap2(int y) {
>     if(y%4 != 0) return false;
>     if(y%100 != 0) return true;
>     if(y%400 != 0) return false;
>     return true;
> }
>
> is even faster (ql / isLeap2 = 40 ). Again be careful with 1900.
>
> Best regards
> Peter
>
>
> On 22 March 2015 at 03:02, Alexander Lamana <[hidden email]> wrote:
>> Hi,
>>
>> I was looking at date.cpp and noticed this [0]. I realize that 2200 is far
>> off, but this section made me wince.
>>
>> Is there any interest in (or reason against) redoing this section so that it
>> lazily populates an array, instead of having one hard coded? I have some
>> spare time this weekend.
>>
>> [0]
>> https://github.com/lballabio/quantlib/blob/master/QuantLib/ql/time/date.cpp#L208
>>
>>
>> Thanks,
>> Alex
>>
>> ------------------------------------------------------------------------------
>> Dive into the World of Parallel Programming The Go Parallel Website,
>> sponsored
>> by Intel and developed in partnership with Slashdot Media, is your hub for
>> all
>> things parallel software development, from weekly thought leadership blogs
>> to
>> news, videos, case studies, tutorials and more. Take a look and join the
>> conversation now. http://goparallel.sourceforge.net/
>> _______________________________________________
>> QuantLib-dev mailing list
>> [hidden email]
>> https://lists.sourceforge.net/lists/listinfo/quantlib-dev
>>

------------------------------------------------------------------------------
Dive into the World of Parallel Programming The Go Parallel Website, sponsored
by Intel and developed in partnership with Slashdot Media, is your hub for all
things parallel software development, from weekly thought leadership blogs to
news, videos, case studies, tutorials and more. Take a look and join the
conversation now. http://goparallel.sourceforge.net/
_______________________________________________
QuantLib-dev mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-dev
Reply | Threaded
Open this post in threaded view
|

Re: Leap Years in the Date class

Luigi Ballabio
Klaus did some work to use Boost.Date to implement our dates. It's in pull request <https://github.com/lballabio/quantlib/pull/186>. If it doesn't decrease performances, I'd rather go that way instead of implementing date calculations again. Alexander, do you have time to do some tests?

Luigi

On Sun, Mar 22, 2015 at 10:14 AM, Peter Caspers <[hidden email]> wrote:
in which the perfomance numbers above depend a lot on the test loop
setup, the compiler seems to apply some clever optimizations when
using a "regular" year pattern as input to the leap year functions.
With random years, the factors are more like this

ql / boost = 1.0
ql / isLeap2 = 2.7

so not that impressive any more.


On 22 March 2015 at 09:54, Peter Caspers <[hidden email]> wrote:
> Hi Alex,
>
> I am in favour of this. Just note that (at least) you would have to
> take care about Date::yearOffset(...) and Date::maxSerialNumber(...)
> as well when extending the range of possible dates. I am not sure if
> there are other code places to consider, Luigi will be the right
> person to answer that ultimately.
>
> Apart from that I played around a bit and
>
> boost::gregorian::gregorian_calendar::is_leap_year(y)
>
> seems to be faster than the original ql code anyway (only 1900 is
> treated different, ql is following the excel "convention" here). I
> seem to observe a factor ql / boost of around 6.
>
> And this
>
> inline bool isLeap2(int y) {
>     if(y%4 != 0) return false;
>     if(y%100 != 0) return true;
>     if(y%400 != 0) return false;
>     return true;
> }
>
> is even faster (ql / isLeap2 = 40 ). Again be careful with 1900.
>
> Best regards
> Peter
>
>
> On 22 March 2015 at 03:02, Alexander Lamana <[hidden email]> wrote:
>> Hi,
>>
>> I was looking at date.cpp and noticed this [0]. I realize that 2200 is far
>> off, but this section made me wince.
>>
>> Is there any interest in (or reason against) redoing this section so that it
>> lazily populates an array, instead of having one hard coded? I have some
>> spare time this weekend.
>>
>> [0]
>> https://github.com/lballabio/quantlib/blob/master/QuantLib/ql/time/date.cpp#L208
>>
>>
>> Thanks,
>> Alex
>>
>> ------------------------------------------------------------------------------
>> Dive into the World of Parallel Programming The Go Parallel Website,
>> sponsored
>> by Intel and developed in partnership with Slashdot Media, is your hub for
>> all
>> things parallel software development, from weekly thought leadership blogs
>> to
>> news, videos, case studies, tutorials and more. Take a look and join the
>> conversation now. http://goparallel.sourceforge.net/
>> _______________________________________________
>> QuantLib-dev mailing list
>> [hidden email]
>> https://lists.sourceforge.net/lists/listinfo/quantlib-dev
>>

------------------------------------------------------------------------------
Dive into the World of Parallel Programming The Go Parallel Website, sponsored
by Intel and developed in partnership with Slashdot Media, is your hub for all
things parallel software development, from weekly thought leadership blogs to
news, videos, case studies, tutorials and more. Take a look and join the
conversation now. http://goparallel.sourceforge.net/
_______________________________________________
QuantLib-dev mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-dev



--

------------------------------------------------------------------------------
Dive into the World of Parallel Programming The Go Parallel Website, sponsored
by Intel and developed in partnership with Slashdot Media, is your hub for all
things parallel software development, from weekly thought leadership blogs to
news, videos, case studies, tutorials and more. Take a look and join the
conversation now. http://goparallel.sourceforge.net/
_______________________________________________
QuantLib-dev mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-dev
Reply | Threaded
Open this post in threaded view
|

Re: Leap Years in the Date class

alex
Yeah, sure. I'll take a look.

On Sun, Mar 22, 2015 at 8:26 AM, Luigi Ballabio <[hidden email]> wrote:
Klaus did some work to use Boost.Date to implement our dates. It's in pull request <https://github.com/lballabio/quantlib/pull/186>. If it doesn't decrease performances, I'd rather go that way instead of implementing date calculations again. Alexander, do you have time to do some tests?

Luigi

On Sun, Mar 22, 2015 at 10:14 AM, Peter Caspers <[hidden email]> wrote:
in which the perfomance numbers above depend a lot on the test loop
setup, the compiler seems to apply some clever optimizations when
using a "regular" year pattern as input to the leap year functions.
With random years, the factors are more like this

ql / boost = 1.0
ql / isLeap2 = 2.7

so not that impressive any more.


On 22 March 2015 at 09:54, Peter Caspers <[hidden email]> wrote:
> Hi Alex,
>
> I am in favour of this. Just note that (at least) you would have to
> take care about Date::yearOffset(...) and Date::maxSerialNumber(...)
> as well when extending the range of possible dates. I am not sure if
> there are other code places to consider, Luigi will be the right
> person to answer that ultimately.
>
> Apart from that I played around a bit and
>
> boost::gregorian::gregorian_calendar::is_leap_year(y)
>
> seems to be faster than the original ql code anyway (only 1900 is
> treated different, ql is following the excel "convention" here). I
> seem to observe a factor ql / boost of around 6.
>
> And this
>
> inline bool isLeap2(int y) {
>     if(y%4 != 0) return false;
>     if(y%100 != 0) return true;
>     if(y%400 != 0) return false;
>     return true;
> }
>
> is even faster (ql / isLeap2 = 40 ). Again be careful with 1900.
>
> Best regards
> Peter
>
>
> On 22 March 2015 at 03:02, Alexander Lamana <[hidden email]> wrote:
>> Hi,
>>
>> I was looking at date.cpp and noticed this [0]. I realize that 2200 is far
>> off, but this section made me wince.
>>
>> Is there any interest in (or reason against) redoing this section so that it
>> lazily populates an array, instead of having one hard coded? I have some
>> spare time this weekend.
>>
>> [0]
>> https://github.com/lballabio/quantlib/blob/master/QuantLib/ql/time/date.cpp#L208
>>
>>
>> Thanks,
>> Alex
>>
>> ------------------------------------------------------------------------------
>> Dive into the World of Parallel Programming The Go Parallel Website,
>> sponsored
>> by Intel and developed in partnership with Slashdot Media, is your hub for
>> all
>> things parallel software development, from weekly thought leadership blogs
>> to
>> news, videos, case studies, tutorials and more. Take a look and join the
>> conversation now. http://goparallel.sourceforge.net/
>> _______________________________________________
>> QuantLib-dev mailing list
>> [hidden email]
>> https://lists.sourceforge.net/lists/listinfo/quantlib-dev
>>

------------------------------------------------------------------------------
Dive into the World of Parallel Programming The Go Parallel Website, sponsored
by Intel and developed in partnership with Slashdot Media, is your hub for all
things parallel software development, from weekly thought leadership blogs to
news, videos, case studies, tutorials and more. Take a look and join the
conversation now. http://goparallel.sourceforge.net/
_______________________________________________
QuantLib-dev mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-dev



--


------------------------------------------------------------------------------
Dive into the World of Parallel Programming The Go Parallel Website, sponsored
by Intel and developed in partnership with Slashdot Media, is your hub for all
things parallel software development, from weekly thought leadership blogs to
news, videos, case studies, tutorials and more. Take a look and join the
conversation now. http://goparallel.sourceforge.net/
_______________________________________________
QuantLib-dev mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-dev